ListBox.xaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. mc:Ignorable="d">
  7. <Style TargetType="{x:Type ListBox}">
  8. <Setter Property="Foreground" Value="{DynamicResource FG_Black}"/>
  9. <Setter Property="FontFamily" Value="Arial"/>
  10. <Setter Property="FontSize" Value="12"/>
  11. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
  12. <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
  13. <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
  14. <Setter Property="VerticalContentAlignment" Value="top"/>
  15. <Setter Property="Template">
  16. <Setter.Value>
  17. <ControlTemplate TargetType="{x:Type ListBox}">
  18. <Border x:Name="Bd" SnapsToDevicePixels="true">
  19. <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
  20. <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
  21. </ScrollViewer>
  22. </Border>
  23. <ControlTemplate.Triggers>
  24. <Trigger Property="IsEnabled" Value="false"/>
  25. <Trigger Property="IsGrouping" Value="true">
  26. <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
  27. </Trigger>
  28. </ControlTemplate.Triggers>
  29. </ControlTemplate>
  30. </Setter.Value>
  31. </Setter>
  32. </Style>
  33. <!--<Style TargetType="{x:Type ListBoxItem}">
  34. <Setter Property="Margin" Value="0"/>
  35. <Setter Property="Padding" Value="0"/>
  36. <Setter Property="BorderThickness" Value="1"/>
  37. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  38. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  39. <Setter Property="Template">
  40. <Setter.Value>
  41. <ControlTemplate TargetType="{x:Type ListBoxItem}">
  42. <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
  43. <Grid>
  44. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Cursor="Arrow" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  45. </Grid>
  46. </Border>
  47. <ControlTemplate.Triggers>
  48. <Trigger Property="IsSelected" Value="true">
  49. <Setter Property="Background" Value="Blue"/>
  50. <Setter Property="Foreground" Value="White"/>
  51. </Trigger>
  52. <Trigger Property="IsEnabled" Value="false">
  53. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
  54. </Trigger>
  55. </ControlTemplate.Triggers>
  56. </ControlTemplate>
  57. </Setter.Value>
  58. </Setter>
  59. </Style>-->
  60. <Style TargetType="{x:Type ListBoxItem}">
  61. <Setter Property="Background" Value="Transparent"/>
  62. <Setter Property="Margin" Value="0"/>
  63. <Setter Property="Padding" Value="0"/>
  64. <Setter Property="BorderThickness" Value="0"/>
  65. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  66. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  67. <Setter Property="Template">
  68. <Setter.Value>
  69. <ControlTemplate TargetType="{x:Type ListBoxItem}">
  70. <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}">
  71. <Grid>
  72. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Cursor="Hand" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  73. <Rectangle x:Name="Highlight" StrokeThickness="1" Opacity="0"/>
  74. </Grid>
  75. </Border>
  76. <ControlTemplate.Triggers>
  77. <Trigger Property="IsSelected" Value="true">
  78. <Setter Property="Stroke" TargetName="Highlight" Value="Yellow"/>
  79. <Setter Property="Opacity" TargetName="Highlight" Value="1"/>
  80. <Setter Property="Foreground" Value="{DynamicResource FG_Black}"/>
  81. <Setter Property="Background" Value="Blue"/>
  82. <Setter Property="Foreground" Value="White"/>
  83. </Trigger>
  84. <Trigger Property="IsEnabled" Value="false">
  85. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
  86. </Trigger>
  87. </ControlTemplate.Triggers>
  88. </ControlTemplate>
  89. </Setter.Value>
  90. </Setter>
  91. </Style>
  92. <Style x:Key="NoSelectionListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
  93. <Setter Property="Background" Value="Transparent"/>
  94. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  95. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  96. <Setter Property="Padding" Value="2,0,0,0"/>
  97. <Setter Property="FocusVisualStyle">
  98. <Setter.Value>
  99. <Style>
  100. <!-- This removes focus visualization -->
  101. <Setter Property="Control.Template" Value="{x:Null}"/>
  102. </Style>
  103. </Setter.Value>
  104. </Setter>
  105. <Setter Property="Template">
  106. <Setter.Value>
  107. <ControlTemplate TargetType="{x:Type ListBoxItem}">
  108. <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
  109. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  110. </Border>
  111. <ControlTemplate.Triggers>
  112. <Trigger Property="IsEnabled" Value="false">
  113. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
  114. </Trigger>
  115. <!-- Some default triggers removed to avoid background changes on selection -->
  116. </ControlTemplate.Triggers>
  117. </ControlTemplate>
  118. </Setter.Value>
  119. </Setter>
  120. </Style>
  121. <Style x:Key="Sepcial_ListBoxItem" TargetType="{x:Type ListBoxItem}">
  122. <Setter Property="Background" Value="Transparent"/>
  123. <Setter Property="Margin" Value="0"/>
  124. <Setter Property="Padding" Value="0"/>
  125. <Setter Property="BorderThickness" Value="0"/>
  126. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  127. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  128. <Setter Property="Template">
  129. <Setter.Value>
  130. <ControlTemplate TargetType="{x:Type ListBoxItem}">
  131. <Border x:Name="Bd" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
  132. <Grid>
  133. <Border x:Name="Highlight" BorderBrush="Black" BorderThickness="0" Background="{DynamicResource Listview_BG_Highlight}" Opacity="0"/>
  134. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Cursor="Hand" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  135. </Grid>
  136. </Border>
  137. <ControlTemplate.Triggers>
  138. <Trigger Property="IsSelected" Value="true">
  139. <Setter Property="Opacity" TargetName="Highlight" Value="1"/>
  140. <Setter Property="BorderThickness" TargetName="Highlight" Value="1"/>
  141. <Setter Property="Foreground" Value="{DynamicResource FG_White}"/>
  142. <Setter Property="Margin" TargetName="Highlight" Value="0,0,1,1"/>
  143. </Trigger>
  144. <Trigger Property="IsMouseOver" Value="True">
  145. <Setter Property="Opacity" TargetName="Highlight" Value="0.8"/>
  146. </Trigger>
  147. <Trigger Property="IsEnabled" Value="false">
  148. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
  149. </Trigger>
  150. </ControlTemplate.Triggers>
  151. </ControlTemplate>
  152. </Setter.Value>
  153. </Setter>
  154. <Style.Triggers>
  155. <Trigger Property="ListBox.AlternationIndex" Value="0">
  156. <Setter Property="Background" Value="{DynamicResource Listview_BG_First}"/>
  157. </Trigger>
  158. <Trigger Property="ListBox.AlternationIndex" Value="1">
  159. <Setter Property="Background" Value="{DynamicResource Listview_BG_Second}"/>
  160. </Trigger>
  161. </Style.Triggers>
  162. </Style>
  163. </ResourceDictionary>