【发布时间】:2013-02-09 06:12:25
【问题描述】:
我需要在整个应用程序中使用相同的视觉样式设置多个GridView。此样式包括自定义ItemsPanel 属性以及GroupStyle 属性。
我的问题是GridView 的GroupStyle 属性不是依赖属性。所以我想写的代码(见下文)不起作用。
您知道在多个GridViews 之间共享样式(包括GroupStyle)的简洁方法吗?
我唯一能想到的是使用GroupStyleSelector,但它有点愚蠢,因为没有选择:它总是使用相同的GroupStyle。此外,我怀疑它不会在设计时反映在 VS & Blend 中。
我想使用的代码:
<GridView
ItemsSource="..."
ItemTemplate="..."
Style="{StaticResource MainMenuStyle}"/>
<Style TargetType="GridView" x:Key="MainMenuStyle">
<Setter Property="ItemsPanel">
<Setter.Value>
...
</Setter.Value>
</Setter>
<Setter Property="GroupStyle">
<Setter.Value>
<GroupStyle>
...
</GroupStyle>
</Setter.Value>
</Setter>
</Style>
【问题讨论】:
-
您能否按照您想要的方式将您的网格布局设置为
UserControl并公开诸如“ItemsSource”之类的依赖属性,以便您可以将其应用于实例,以便您回收相同的模板,但仍填充不同的数据? -
是的,看起来像是查看答案的方式。还没有了解
UserControl,似乎是开始的好时机。
标签: xaml gridview windows-8 winrt-xaml