ListBox.xaml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  3. <!--默认样式-->
  4. <Style BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox"/>
  5. <Style x:Key="ListBoxItemBaseStyle.Small" BasedOn="{StaticResource ListBoxItemBaseStyle}" TargetType="ListBoxItem">
  6. <Setter Property="Padding" Value="6,0"/>
  7. <Setter Property="MinHeight" Value="24"/>
  8. </Style>
  9. <Style x:Key="ListBox.Small" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox">
  10. <Setter Property="ItemContainerStyle" Value="{StaticResource ListBoxItemBaseStyle.Small}"/>
  11. </Style>
  12. <Style x:Key="ListBoxItemCustom" TargetType="ListBoxItem">
  13. <Setter Property="SnapsToDevicePixels" Value="True"/>
  14. <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
  15. <Setter Property="Padding" Value="0"/>
  16. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType=ItemsControl}}"/>
  17. <Setter Property="VerticalContentAlignment" Value="Top"/>
  18. <Setter Property="Background" Value="Transparent"/>
  19. <Setter Property="BorderBrush" Value="Transparent"/>
  20. <Setter Property="BorderThickness" Value="0"/>
  21. <Setter Property="Template">
  22. <Setter.Value>
  23. <ControlTemplate TargetType="ListBoxItem">
  24. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  25. </ControlTemplate>
  26. </Setter.Value>
  27. </Setter>
  28. </Style>
  29. <Style x:Key="ListBoxCustom" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox">
  30. <Setter Property="ItemContainerStyle" Value="{StaticResource ListBoxItemCustom}"/>
  31. <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
  32. </Style>
  33. <Style x:Key="WrapPanelHorizontalListBox" BasedOn="{StaticResource ListBoxCustom}" TargetType="ListBox">
  34. <Setter Property="ItemsPanel" Value="{StaticResource WrapHorizontalItemsPanelTemplate}"/>
  35. </Style>
  36. <Style x:Key="WrapPanelVerticalListBox" BasedOn="{StaticResource ListBoxCustom}" TargetType="ListBox">
  37. <Setter Property="ItemsPanel" Value="{StaticResource WrapVerticalItemsPanelTemplate}"/>
  38. </Style>
  39. <Style x:Key="StackPanelHorizontalListBox" BasedOn="{StaticResource ListBoxCustom}" TargetType="ListBox">
  40. <Setter Property="ItemsPanel" Value="{StaticResource StackHorizontalItemsPanelTemplate}"/>
  41. </Style>
  42. <Style x:Key="StackPanelVerticalListBox" BasedOn="{StaticResource ListBoxCustom}" TargetType="ListBox">
  43. <Setter Property="ItemsPanel" Value="{StaticResource StackVerticalItemsPanelTemplate}"/>
  44. </Style>
  45. </ResourceDictionary>