使用<scrollviewer> xaml </scrollviewer>时出错

时间:2012-04-13 13:50:09

标签: windows-phone-7 xaml

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

<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>

2 个答案:

答案 0 :(得分:3)

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>

答案 1 :(得分:0)

将您的<TextBlock><TextBox>放在另一个容器中,例如StackPanel。