ListBox.xaml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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="Background" Value="Transparent"/>
  35. <Setter Property="Margin" Value="0"/>
  36. <Setter Property="Padding" Value="0"/>
  37. <Setter Property="BorderThickness" Value="0"/>
  38. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  39. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  40. <Setter Property="Template">
  41. <Setter.Value>
  42. <ControlTemplate TargetType="{x:Type ListBoxItem}">
  43. <Border x:Name="Bd" SnapsToDevicePixels="true">
  44. <Grid>
  45. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Cursor="Hand" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  46. <Rectangle x:Name="Highlight" StrokeThickness="1" Opacity="0"/>
  47. </Grid>
  48. </Border>
  49. <ControlTemplate.Triggers>
  50. <Trigger Property="IsSelected" Value="true">
  51. <Setter Property="Stroke" TargetName="Highlight" Value="Yellow"/>
  52. <Setter Property="Opacity" TargetName="Highlight" Value="1"/>
  53. <Setter Property="Foreground" Value="{DynamicResource FG_Black}"/>
  54. </Trigger>
  55. <Trigger Property="IsEnabled" Value="false">
  56. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
  57. </Trigger>
  58. </ControlTemplate.Triggers>
  59. </ControlTemplate>
  60. </Setter.Value>
  61. </Setter>
  62. </Style>
  63. <Style x:Key="NoSelectionListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
  64. <Setter Property="Background" Value="Transparent"/>
  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="Padding" Value="2,0,0,0"/>
  68. <Setter Property="FocusVisualStyle">
  69. <Setter.Value>
  70. <Style>
  71. <!-- This removes focus visualization -->
  72. <Setter Property="Control.Template" Value="{x:Null}"/>
  73. </Style>
  74. </Setter.Value>
  75. </Setter>
  76. <Setter Property="Template">
  77. <Setter.Value>
  78. <ControlTemplate TargetType="{x:Type ListBoxItem}">
  79. <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
  80. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  81. </Border>
  82. <ControlTemplate.Triggers>
  83. <Trigger Property="IsEnabled" Value="false">
  84. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
  85. </Trigger>
  86. <!-- Some default triggers removed to avoid background changes on selection -->
  87. </ControlTemplate.Triggers>
  88. </ControlTemplate>
  89. </Setter.Value>
  90. </Setter>
  91. </Style>
  92. <Style x:Key="Sepcial_ListBoxItem" TargetType="{x:Type ListBoxItem}">
  93. <Setter Property="Background" Value="Transparent"/>
  94. <Setter Property="Margin" Value="0"/>
  95. <Setter Property="Padding" Value="0"/>
  96. <Setter Property="BorderThickness" Value="0"/>
  97. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  98. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  99. <Setter Property="Template">
  100. <Setter.Value>
  101. <ControlTemplate TargetType="{x:Type ListBoxItem}">
  102. <Border x:Name="Bd" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
  103. <Grid>
  104. <Border x:Name="Highlight" BorderBrush="Black" BorderThickness="0" Background="{DynamicResource Listview_BG_Highlight}" Opacity="0"/>
  105. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Cursor="Hand" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  106. </Grid>
  107. </Border>
  108. <ControlTemplate.Triggers>
  109. <Trigger Property="IsSelected" Value="true">
  110. <Setter Property="Opacity" TargetName="Highlight" Value="1"/>
  111. <Setter Property="BorderThickness" TargetName="Highlight" Value="1"/>
  112. <Setter Property="Foreground" Value="{DynamicResource FG_White}"/>
  113. <Setter Property="Margin" TargetName="Highlight" Value="0,0,1,1"/>
  114. </Trigger>
  115. <Trigger Property="IsMouseOver" Value="True">
  116. <Setter Property="Opacity" TargetName="Highlight" Value="0.8"/>
  117. </Trigger>
  118. <Trigger Property="IsEnabled" Value="false">
  119. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
  120. </Trigger>
  121. </ControlTemplate.Triggers>
  122. </ControlTemplate>
  123. </Setter.Value>
  124. </Setter>
  125. <Style.Triggers>
  126. <Trigger Property="ListBox.AlternationIndex" Value="0">
  127. <Setter Property="Background" Value="{DynamicResource Listview_BG_First}"/>
  128. </Trigger>
  129. <Trigger Property="ListBox.AlternationIndex" Value="1">
  130. <Setter Property="Background" Value="{DynamicResource Listview_BG_Second}"/>
  131. </Trigger>
  132. </Style.Triggers>
  133. </Style>
  134. </ResourceDictionary>