code_junkie

Changing (Enable/Disable) GroupStyle in ListView for different category items

Nov 11th, 2011
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. <Style x:Key="grouping"
  2. TargetType="{x:Type GroupStyle}">
  3. <Setter Property="ContainerStyle">
  4. <Setter.Value>
  5. <Style TargetType="{x:Type GroupItem}">
  6. <Setter Property="Margin"
  7. Value="0,0,0,5" />
  8. <Setter Property="Template">
  9. <Setter.Value>
  10. <ControlTemplate TargetType="{x:Type GroupItem}">
  11. <Expander IsExpanded="False"
  12. BorderBrush="#FFA4B97F"
  13. BorderThickness="0,0,0,1">
  14. <Expander.Header>
  15. <DockPanel>
  16. <TextBlock FontWeight="Bold"
  17. Text="{Binding Name}"
  18. Margin="0"
  19. Width="250" />
  20. <TextBlock FontWeight="Bold"
  21. Text="{Binding Path=Items[0].StartTime, StringFormat=T}" />
  22. </DockPanel>
  23. </Expander.Header>
  24. <Expander.Content>
  25. <ItemsPresenter />
  26. </Expander.Content>
  27. </Expander>
  28. </ControlTemplate>
  29. </Setter.Value>
  30. </Setter>
  31. </Style>
  32. </Setter.Value>
  33. </Setter>
  34. </Style>
  35.  
  36. <ControlTemplate TargetType="{x:Type GroupItem}"
  37. x:Key="defaultGroup">
  38. <ItemsPresenter />
  39. </ControlTemplate>
  40.  
  41. <ListView.GroupStyle>
  42. <GroupStyle >
  43. <GroupStyle.ContainerStyle>
  44. <Style TargetType="{x:Type GroupItem}">
  45. <Setter Property="Margin"
  46. Value="0,0,0,5" />
  47. <Setter Property="Template">
  48. <Setter.Value>
  49. <ControlTemplate TargetType="{x:Type GroupItem}">
  50. <Expander IsExpanded="False"
  51. BorderBrush="Black"
  52. BorderThickness="3"
  53. Padding="5,1,1,5">
  54. <Expander.Header>
  55. <DockPanel>
  56. <TextBlock FontWeight="Bold"
  57. Margin="0"
  58. Width="250">
  59. <TextBlock.Text>
  60. <MultiBinding StringFormat="{}{0} ({1} jobs)">
  61. <Binding Path="Name" />
  62. <Binding Path="ItemCount" />
  63. </MultiBinding>
  64. </TextBlock.Text>
  65. </TextBlock>
  66. <TextBlock FontWeight="Bold"
  67. Text="{Binding Path=Items[0].Category, StringFormat=T}" />
  68. </DockPanel>
  69. </Expander.Header>
  70. <Expander.Content>
  71. <ItemsPresenter />
  72. </Expander.Content>
  73. </Expander>
  74. </ControlTemplate>
  75. </Setter.Value>
  76. </Setter>
  77. <Style.Triggers>
  78. <DataTrigger Binding="{Binding Items[0].Category}"
  79. Value="ABC">
  80. <Setter Property="Template"
  81. Value="{StaticResource defaultGroup}" />
  82. </DataTrigger>
  83. </Style.Triggers>
  84. </Style>
  85. </GroupStyle.ContainerStyle>
  86. </GroupStyle>
  87. </ListView.GroupStyle>
Add Comment
Please, Sign In to add comment