ImageButtonStyle.xaml 7.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:customControl="clr-namespace:PDF_Master.CustomControl">
  5. <Style TargetType="{x:Type customControl:ImageButton}">
  6. <Setter Property="Background" Value="Transparent" />
  7. <Setter Property="Template">
  8. <Setter.Value>
  9. <ControlTemplate TargetType="{x:Type customControl:ImageButton}">
  10. <Border
  11. Background="{TemplateBinding Background}"
  12. BorderBrush="{TemplateBinding BorderBrush}"
  13. BorderThickness="{TemplateBinding BorderThickness}">
  14. <Grid x:Name="grid" Background="{TemplateBinding Background}">
  15. <Border
  16. x:Name="PART_Border"
  17. Background="{TemplateBinding Background}"
  18. BorderBrush="{TemplateBinding BorderBrush}"
  19. BorderThickness="{TemplateBinding BorderThickness}"
  20. CornerRadius="{TemplateBinding CornerRadius}" />
  21. <Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
  22. <StackPanel
  23. Margin="{TemplateBinding Padding}"
  24. HorizontalAlignment="Center"
  25. VerticalAlignment="Center"
  26. Orientation="{TemplateBinding IconContentOrientation}">
  27. <Grid HorizontalAlignment="Center" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
  28. <Image
  29. x:Name="PART_Icon"
  30. Width="{TemplateBinding IconWidth}"
  31. Height="{TemplateBinding IconHeight}"
  32. Source="{TemplateBinding Icon}" />
  33. <Image
  34. x:Name="PART_MouseOverIcon"
  35. Width="{TemplateBinding IconWidth}"
  36. Height="{TemplateBinding IconHeight}"
  37. Source="{TemplateBinding IconMouseOver}"
  38. Visibility="Collapsed" />
  39. <Image
  40. x:Name="PART_PressIcon"
  41. Width="{TemplateBinding IconWidth}"
  42. Height="{TemplateBinding IconHeight}"
  43. Source="{TemplateBinding IconPress}"
  44. Visibility="Collapsed" />
  45. </Grid>
  46. <TextBlock
  47. x:Name="PART_Content"
  48. Margin="{TemplateBinding IconContentMargin}"
  49. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  50. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  51. Foreground="{TemplateBinding Foreground}"
  52. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  53. Text="{TemplateBinding Content}"
  54. TextTrimming="CharacterEllipsis" />
  55. </StackPanel>
  56. </Grid>
  57. </Grid>
  58. </Border>
  59. <ControlTemplate.Triggers>
  60. <Trigger Property="IsMouseOver" Value="True">
  61. <Setter TargetName="PART_Content" Property="Foreground" Value="{Binding MouseOverForeground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
  62. <Setter TargetName="PART_Border" Property="Background" Value="{Binding MouseOverBackground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
  63. <Setter TargetName="PART_Border" Property="Opacity" Value="{Binding MouseOverBackgroundOpacity, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
  64. <Setter TargetName="PART_Border" Property="BorderBrush" Value="{Binding MouseOverBorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
  65. <Setter TargetName="PART_MouseOverIcon" Property="Visibility" Value="Visible" />
  66. <Setter TargetName="PART_Icon" Property="Visibility" Value="Collapsed" />
  67. <Setter TargetName="PART_PressIcon" Property="Visibility" Value="Collapsed" />
  68. </Trigger>
  69. <Trigger Property="IsPressed" Value="True">
  70. <Setter TargetName="PART_Content" Property="Foreground" Value="{Binding MouseDownForeground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
  71. <Setter TargetName="PART_Border" Property="Background" Value="{Binding MouseDownBackground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
  72. <Setter TargetName="PART_Border" Property="BorderBrush" Value="{Binding MouseDownBorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
  73. <Setter TargetName="PART_PressIcon" Property="Visibility" Value="Visible" />
  74. <Setter TargetName="PART_Icon" Property="Visibility" Value="Collapsed" />
  75. <Setter TargetName="PART_MouseOverIcon" Property="Visibility" Value="Collapsed" />
  76. </Trigger>
  77. <Trigger Property="IsEnabled" Value="False">
  78. <Setter Property="Opacity" Value="0.5" />
  79. </Trigger>
  80. <Trigger SourceName="PART_Content" Property="Text" Value="">
  81. <Setter TargetName="PART_Content" Property="Visibility" Value="Collapsed" />
  82. </Trigger>
  83. <Trigger SourceName="PART_Content" Property="Text" Value="{x:Null}">
  84. <Setter TargetName="PART_Content" Property="Visibility" Value="Collapsed" />
  85. </Trigger>
  86. </ControlTemplate.Triggers>
  87. </ControlTemplate>
  88. </Setter.Value>
  89. </Setter>
  90. </Style>
  91. </ResourceDictionary>