我正在爲Windows 8開發一個應用程序metro。我使用GridApp(xaml)項目,但我想在每個部分中使用不同的組風格。在gridview中選擇組風格
我的代碼是:
public class GroupTemplateSelector : GroupStyleSelector
{
public GroupStyle NewsItemGroupStyle { get; set; }
public GroupStyle NormalGroupStyle { get; set; }
protected override GroupStyle SelectGroupStyleCore(object group, uint level)
{
// a method that tries to grab an enum off the bound data object
if (level == 3)
{
return NewsItemGroupStyle;
}
else
{
return NormalGroupStyle;
}
throw new ArgumentException("Unexpected group type");
}
}
我使用這個類選擇器組風格和XAML
<!-- NewsItemGroupStyle -->
<GroupStyle x:Key="NewsItemGroupStyle">
<GroupStyle.HeaderTemplate>
<DataTemplate>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" Margin="0,0,80,0" VerticalAlignment="Bottom"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
<!-- NormalItemGroupStyle -->
<GroupStyle x:Key="NormalGroupStyle">
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button
AutomationProperties.Name="Group Title"
Content="{Binding Title}"
Background="Blue"
Click="Header_Click"
Style="{StaticResource TextButtonStyle}"
/>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
<!-- selector -->
<common:GroupTemplateSelector
x:Key="groupSelector"
NewsItemGroupStyle="{StaticResource NewsItemGroupStyle}"
NormalGroupStyle="{StaticResource NormalGroupStyle}" />
但款式組變化的一次。
你可以看到,如果這[主題](http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/在MSDN上的線程/ 63a5d82c-1ad2-4e24-bfb4-122d5551c5f0 /)可以解答你的問題。 – 2012-08-07 16:35:39
而問題是? – Denis 2012-08-10 07:11:18
我有完全相同的問題,每個人都在這個線程http://social.msdn.microsoft.com/Forums/en-GB/winappswithcsharp/thread/5f12273f-e000-4c96-a4bc-6ccc18a104a0 – krisdyson 2012-09-14 15:58:06