【发布时间】:2016-05-22 10:42:34
【问题描述】:
我需要根据参数创建动态行和列,就像在我的 json 中一样,我将有 x 和 y,这将是没有的。分别是行和列,并且会有 x 和 y 的内容,我必须将它们放在各自的行和列中,我尝试使用下面的代码,但发现 UWP 应用程序中没有统一网格。也考虑过 DataTemplateSelector,但不确定使用它是否是个好主意。
Xaml:
<ItemsControl ItemsSource="{Binding MyCollection}">
<!-- This panel will be used to hold the items -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<un Rows="8"
Columns="8" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<!-- Each item will be drawn using this template -->
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding }"
Style="{StaticResource MyButtonStyle}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
请任何人指导我应该遵循什么方法。
【问题讨论】:
-
虽然UWP没有内置UniformGrid,但是我们可以自己实现或者使用第三方的UniformGrid,比如WinRTXamlToolkit。可以参考我的previous answer,可能会有帮助。