【问题标题】:XAML throwing error - 'content' set more than onceXAML 引发错误 - 多次设置“内容”
【发布时间】:2014-01-16 16:04:43
【问题描述】:

我正在尝试设置我的 XAML,以便使用我研究并添加到我的项目中的一些代码。我希望我的 XAML 代码包含以下内容:

        <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="Sample twitter app" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="main page" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>                            
        </Grid.RowDefinitions>

        <phone:WebBrowser Grid.Row="0" Margin="-6,3,0,1" Name="loginBrowserControl" Visibility="Collapsed"
                          Navigated="loginBrowserControl_Navigated" Navigating="loginBrowserControl_Navigating"/>

        <Grid x:Name="TweetPanel" Grid.Row="0" Visibility="Collapsed">
            <TextBlock x:Name="txtUserName" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="26" FontFamily="Segoe WP Bold" Foreground="Red"/>
       </Grid>
    </Grid>

但是,当我尝试使用它时,Visual Studio 给了我错误“属性'内容'被设置了不止一次”。有人知道我需要做些什么改变吗?

谢谢

【问题讨论】:

  • 这个发布的代码没有任何问题...请将您的代码发布在您想要放置的位置(您自己的周围 XAML 代码)!

标签: visual-studio-2010 xaml windows-phone-7


【解决方案1】:

您需要一个围绕代码的布局元素。 Xaml 页面必须有一个根元素。下面是一个使用 Grid 的示例`

<Grid x:Name="LayoutRoot"> ... your code above ... </Grid>

【讨论】:

  • +1 表示需要单个父根元素,但不一定必须仅限于 Grid
【解决方案2】:

试着放一个堆栈面板

 <StackPanel  Grid.Row="0" Orientation="Vertical">
  <phone:WebBrowser  Margin="-6,3,0,1" Name="loginBrowserControl"   Visibility="Collapsed"
   Navigated="loginBrowserControl_Navigated" Navigating="loginBrowserControl_Navigating"/>
  <Grid x:Name="TweetPanel"  Visibility="Collapsed">
        <TextBlock x:Name="txtUserName" VerticalAlignment="Center" HorizontalAlignment="Center"   FontSize="26" FontFamily="Segoe WP Bold" Foreground="Red"/>
   </Grid>
 </StackPanel>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多