【问题标题】:Error when using <Scrollviewer> xaml使用 <Scrollviewer> xaml 时出错
【发布时间】:2012-04-13 13:50:08
【问题描述】:

我正在尝试使用 a 但出现错误: 多次设置“内容”属性。 如果我删除标签之间的两行代码中的任何一行,它就会消失。 因此,它们似乎都不是单独的错误,但两者共同导致了问题。

<Grid x:Name="LayoutRoot" Background="Transparent">

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--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="New Trip" Style="{StaticResource PhoneTextNormalStyle}" Height="40" />
        <Button Content="Back" Height="71" Name="button1" Width="103" HorizontalContentAlignment="Stretch" VerticalAlignment="Top" HorizontalAlignment="Right" Click="button1_Click" />
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ScrollViewer>
            <TextBlock Height="60" HorizontalAlignment="Left" Margin="65,12,0,0" Name="textBlock1" Text="Username" VerticalAlignment="Top" Width="169" />
            <TextBox Height="78" HorizontalAlignment="Left" Margin="60,60,0,0" Name="textBoxUsername"  VerticalAlignment="Top" Width="274"  />
        </ScrollViewer>
    </Grid>

</Grid>

【问题讨论】:

    标签: windows-phone-7 xaml


    【解决方案1】:

    ScrollViewer 只能有 1 个内容,因此将 ScrollViewer 内的控件包装在 Grid、DockPanel、StackPanel 等容器中

          <ScrollViewer>
            <StackPanel>
                <TextBlock Height="60" HorizontalAlignment="Left" Margin="65,12,0,0" Name="textBlock1" Text="Username" VerticalAlignment="Top" Width="169" />
                <TextBox Height="78" HorizontalAlignment="Left" Margin="60,60,0,0" Name="textBoxUsername"  VerticalAlignment="Top" Width="274"  />
            </StackPanel>
          </ScrollViewer>
    

    【讨论】:

      【解决方案2】:

      将您的 &lt;TextBlock&gt;&lt;TextBox&gt; 放在另一个容器中,例如 StackPanel。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-22
        • 1970-01-01
        • 1970-01-01
        • 2015-09-30
        • 1970-01-01
        • 1970-01-01
        • 2018-07-31
        • 2015-09-11
        相关资源
        最近更新 更多