我正在创建一个类似于windows8日历app的应用程序,但我遇到了一个问题。
那么如何在GridView中拉伸我的组以填充所有可用空间(与windows应用程序中的月视图相同)?我试图设置HorizontalContentAlignment
的属性GridViewItem
,但它没有生效。
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<GridView Padding="116,37,40,46" ItemsSource="{Binding Source={StaticResource DayGroups}}">
<GridView.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Day}" />
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</GridView.ItemContainerStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Key}" Style="{StaticResource SubtitleTextBlockStyle}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid />
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
</GridView>
</Grid>
由于
ItemSource只是
的集合 public class GroupViewModel<TKey, TItem> : ViewModelBase
{
private ObservableCollection<TItem> _items;
private TKey _key;
public TKey Key
{
get { return _key; }
set { Set(ref _key, value); }
}
public ObservableCollection<TItem> Items
{
get { return _items; }
set { Set(ref _items, value); }
}
}
其中TKey
为string
,TItem
为DateTime