scrollviewer属性'content'被设置多次

Mar*_*yad 3 wpf xaml microsoft-metro

这是我的代码:

<Grid Style="{StaticResource LayoutRootStyle}">
    <Grid.RowDefinitions>
        <RowDefinition Height="140"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <ScrollViewer 
            Grid.RowSpan="2" Style="{StaticResource HorizontalScrollViewerStyle}"
            HorizontalScrollBarVisibility="Visible" >
            <!-- The elements you want to be horizontally scrollable goes here -->
            <!-- Horizontal scrolling grid used in most view states -->

        <GridView
            Name="itemGridView"
            AutomationProperties.AutomationId="ItemsGridView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Padding="100,136,116,46"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
            ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="ItemView_ItemClick"/>

         <Button Hello />  <!-- From here come the Error -->           
    </ScrollViewer>
</Grid>
Run Code Online (Sandbox Code Playgroud)

当我在我之后添加任何东西时GridView,它会给我这个错误(属性content设置不止一次).

Mat*_*and 9

答案就在错误信息中.A ScrollViewer只能有一个孩子(你有两个,一个GridView和一个Button).如果要添加多个内容,则必须将它们包装在允许多个子项的面板中(例如Grid).