SplitButtonBaseStyle.xaml 6.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:hc="clr-namespace:HandyControl.Controls">
  4. <Style x:Key="SplitButtonBaseStyle" BasedOn="{StaticResource BaseStyle}" TargetType="hc:SplitButton">
  5. <Setter Property="Height" Value="{StaticResource DefaultControlHeight}"/>
  6. <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
  7. <Setter Property="Padding" Value="{StaticResource DefaultControlPadding}"/>
  8. <Setter Property="Foreground" Value="{DynamicResource TextIconBrush}"/>
  9. <Setter Property="BorderThickness" Value="0"/>
  10. <Setter Property="HorizontalAlignment" Value="Center"/>
  11. <Setter Property="VerticalAlignment" Value="Center"/>
  12. <Setter Property="HorizontalContentAlignment" Value="Center"/>
  13. <Setter Property="VerticalContentAlignment" Value="Center"/>
  14. <Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
  15. <Setter Property="hc:BorderElement.CornerRadius" Value="{StaticResource DefaultCornerRadius}"/>
  16. <Setter Property="Template">
  17. <Setter.Value>
  18. <ControlTemplate TargetType="hc:SplitButton">
  19. <hc:SimplePanel x:Name="templateRoot">
  20. <Border Background="{TemplateBinding Background}" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}"/>
  21. <Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}">
  22. <Grid>
  23. <Grid.ColumnDefinitions>
  24. <ColumnDefinition/>
  25. <ColumnDefinition Width="Auto"/>
  26. </Grid.ColumnDefinitions>
  27. <StackPanel Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}">
  28. <Path x:Name="PathMain" Width="{TemplateBinding hc:IconElement.Width}" Height="{TemplateBinding hc:IconElement.Height}" Fill="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Stretch="Uniform" Data="{TemplateBinding hc:IconElement.Geometry}"/>
  29. <ContentPresenter x:Name="ContentPresenterMain" RecognizesAccessKey="True" VerticalAlignment="Center" Margin="6,0,0,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
  30. </StackPanel>
  31. <ToggleButton x:Name="PART_Arrow" hc:IconElement.Width="14" Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessSplitConverter}, ConverterParameter='0,1,1,1'}" Foreground="{TemplateBinding Foreground}" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Height="Auto" Width="Auto" Grid.Column="1" Style="{StaticResource ToggleButtonIconTransparent}" hc:IconSwitchElement.GeometrySelected="{StaticResource UpGeometry}" hc:IconElement.Geometry="{StaticResource DownGeometry}"/>
  32. </Grid>
  33. </Border>
  34. <Popup AllowsTransparency="true" StaysOpen="False" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="Fade" Placement="Bottom">
  35. <Border CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" x:Name="dropDownBorder" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" Background="{DynamicResource RegionBrush}">
  36. <ScrollViewer Margin="0,4" x:Name="DropDownScrollViewer">
  37. <hc:SimplePanel RenderOptions.ClearTypeHint="Enabled">
  38. <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
  39. <Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
  40. </Canvas>
  41. <ContentPresenter ContentSource="DropDownContent"/>
  42. </hc:SimplePanel>
  43. </ScrollViewer>
  44. </Border>
  45. </Popup>
  46. </hc:SimplePanel>
  47. <ControlTemplate.Triggers>
  48. <Trigger Property="Content" Value="{x:Null}">
  49. <Setter Property="Visibility" Value="Collapsed" TargetName="ContentPresenterMain"/>
  50. </Trigger>
  51. <Trigger Property="hc:IconElement.Geometry" Value="{x:Null}">
  52. <Setter Property="Visibility" Value="Collapsed" TargetName="PathMain"/>
  53. <Setter Property="Margin" Value="0" TargetName="ContentPresenterMain"/>
  54. </Trigger>
  55. <MultiTrigger>
  56. <MultiTrigger.Conditions>
  57. <Condition Property="HitMode" Value="Click"/>
  58. <Condition Property="IsChecked" Value="True" SourceName="PART_Arrow"/>
  59. </MultiTrigger.Conditions>
  60. <Setter Property="IsDropDownOpen" Value="True"/>
  61. </MultiTrigger>
  62. </ControlTemplate.Triggers>
  63. </ControlTemplate>
  64. </Setter.Value>
  65. </Setter>
  66. <Style.Triggers>
  67. <Trigger Property="IsMouseOver" Value="True">
  68. <Setter Property="Opacity" Value=".9"/>
  69. </Trigger>
  70. <Trigger Property="IsPressed" Value="True">
  71. <Setter Property="Opacity" Value=".6"/>
  72. </Trigger>
  73. <Trigger Property="IsEnabled" Value="False">
  74. <Setter Property="Opacity" Value="0.4"/>
  75. </Trigger>
  76. </Style.Triggers>
  77. </Style>
  78. </ResourceDictionary>