ImageButtonStyle.xaml 6.8 KB

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