我有一个带有自定义组的网格视图。在MyTemplateSelector : DataTemplateSelector
我定义要使用的模板。使用这篇文章,我创建了以下布局。
如何调整“新闻 1”中第一项的大小以填充整个可用内容?
这是我的网格的代码:
class ResizableGridView : GridView
{
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
var viewModel = item as IResizable;
if (viewModel != null && viewModel.Width != 0 && viewModel.Height != 0)
{
element.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, 2);
element.SetValue(VariableSizedWrapGrid.RowSpanProperty, 2);
}
base.PrepareContainerForItemOverride(element, item);
}
}
<resizeableGrid:ResizableGridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemGridView"
AutomationProperties.Name="Grouped Items"
Grid.Column="3"
Padding="116,137,40,46"
ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
ItemTemplateSelector="{StaticResource mySelector}"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick">
以及使用的项目模板的代码。
<DataTemplate x:Key="tmp170x170ItemTemplate">
<Grid HorizontalAlignment="Left" Width="170" Height="170">
<Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
<Image Source="{Binding Image}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/>
</Border>
<StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
<TextBlock Text="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextStyle}" Height="30" Margin="15,0,15,0"/>
<TextBlock Text="{Binding Subtitle}" Foreground="{StaticResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="15,0,15,10"/>
</StackPanel>
</Grid>
</DataTemplate>