我正在使用带有模板选择器的 GridView 并在后面的代码中传递项目源。问题在于 VariableSizedWrapGrid 真的很慢,传递的集合大约有 80 项大(集合由几个字符串组成)。删除 variableSizedWrapGrid 解决了这个问题,但给我留下了宽度较小的模板之间的大间隙。
这是网格视图:
<SemanticZoom x:Name="Zoom" Grid.Row="1" IsZoomedInViewActive="False" ViewChangeStarted="Zoom_ViewChangeStarted_1" IsZoomOutButtonEnabled="False" Margin="0,0,0,29" Grid.RowSpan="2">
<SemanticZoom.ZoomedInView>
<!-- Horizontal scrolling grid used in most view states -->
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemsGridView"
AutomationProperties.Name="Items"
TabIndex="1"
ItemTemplateSelector="{StaticResource DayTemplateSelector}"
SelectionMode="None"
IsSwipeEnabled="True"
ItemContainerStyle="{StaticResource GridViewItemStyle1}"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
IsItemClickEnabled="True"
ScrollViewer.IsHorizontalScrollChainingEnabled="False"
ItemClick="ItemView_ItemClick">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid ItemWidth="380" ItemHeight="500"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</SemanticZoom.ZoomedInView>
和模板选择器:
class DayTemplateSelecter : DataTemplateSelector
{
public DataTemplate DayOffTemplate { get; set; }
public DataTemplate DutyTemplate { get; set; }
public DataTemplate RestTemplate { get; set; }
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
var templateItem = item as DutyItem;
var element = container as FrameworkElement;
if (templateItem.Trip.Count > 0 || templateItem.OtherTrip.Count > 0)
{
container.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, 2);
return DutyTemplate;
}
else if (templateItem.Codes.Count > 0)
{
container.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, 1);
return DayOffTemplate;
}
else
{
container.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, 1);
return RestTemplate;
}
}
}
我不认为这会有如此大的性能差异。. 仅使用 variableSized 会使页面延迟 3 秒,这在某些低端平板电脑上甚至更大。
我做错了吗,有没有更好的方法来做到这一点?