我使用的是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>
答案 0 :(得分:0)
通常,GridView绑定到ViewModel的集合。大多数人通常会在其集合的每个组中添加一个“空白/空”ViewModel,并让GridView交换模板以用于使用ItemTemplateSelector渲染ViewModel。
看看问题WinRT gridview Add tile作为参考点。这里有一个很棒的示例实现。
这里还有一段视频,展示了从14:23开始进入视频的这个概念。 http://channel9.msdn.com/Series/Migrating-apps-from-Windows-Phone-to-Windows-8/Binding-the-Interface-in-Windows-Store-apps