1

我正在使用 GroupedItemsPage.xaml。我已将项目源设置为组列表,其中“组”是我的自定义类,它显示不同的组及其项目。我的问题是我想为每个组添加一个“添加”按钮,以便每次加载组时,无论该组中是否有项目,都会显示“添加”按钮。在此处输入图像描述 第一张图片是我希望我的小组在添加一些项目后的样子。第二张图片是我希望我的组在没有添加任何项目时的样子。我该如何进行?我正在使用以下网格视图样式。

 <Style TargetType="GridView" x:Key="GridViewStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="GridView">
                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}">
                        <ScrollViewer x:Name="ScrollViewer"
                                      TabNavigation="{TemplateBinding TabNavigation}"
                                      HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
                                      HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                      IsHorizontalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsHorizontalScrollChainingEnabled}"
                                      VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
                                      VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                      IsVerticalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsVerticalScrollChainingEnabled}"
                                      IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
                                      IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
                                      ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}"
                                      IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                                      BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}">
                            <Grid Height="765" Width="2666" Margin="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>

                                <!-- Your custom buttons -->
                                <Grid x:Name="myGrid" HorizontalAlignment="Left" Width="1108" DataContext="{Binding RelativeSource={RelativeSource Self}}" >
                                    <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Margin="0,0,10,0">
                                        <Image Source="Assets/Untitled.png" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/>
                                    </Border>
                                    <StackPanel VerticalAlignment="Top"  Height="755" Margin="0,0,0,0">

                                        <TextBlock Text="RoleCenter"   Style="{StaticResource PageHeaderTextStyle}" Height="77" Margin="140,50,0,0"/>
                                        <TextBlock Text="{Binding x}" Style="{StaticResource PageHeaderTextStyle}" Height="77" Margin="140,300"/>
                                    </StackPanel>

                                </Grid>


                                <ItemsPresenter
                                            HeaderTemplate="{TemplateBinding HeaderTemplate}"
                                            Header="{TemplateBinding Header}"
                                            HeaderTransitions="{TemplateBinding HeaderTransitions}"

                                            Padding="{TemplateBinding Padding}" Margin="1113,10,244,0" />

                                <StackPanel Width="150" Height="150" Background="#006AC1" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,100,0">
                                    <Button x:Name="LoadMore" Content="+" Height="150" Click="Navigate"  Width="150" />


                                </StackPanel>
                            </Grid>
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
4

1 回答 1

0

通常,GridView 绑定到 ViewModel 的集合。大多数人通常将“空白/空”视图模型添加到他们集合的每一组,并让 GridView 换出模板以使用 ItemTemplateSelector 呈现该视图模型。

看看 SO question WinRT gridview Add tile as a point of reference。那里显示了一个很好的示例实现。

这也是一个视频,它从视频的 14:23 开始展示了这个概念。http://channel9.msdn.com/Series/Migrating-apps-from-Windows-Phone-to-Windows-8/Binding-the-Interface-in-Windows-Store-apps

于 2013-05-01T16:53:30.093 回答