zoukankan      html  css  js  c++  java
  • WPF Style Setter use a TemplateBinding?

     <Style TargetType="{x:Type local:ImageButton}">
            <Setter Property="HorizontalContentAlignment"
                    Value="Center"></Setter>
            <Setter Property="VerticalContentAlignment"
                    Value="Center"></Setter>
            <Setter Property="Foreground"
                    Value="White"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:ImageButton}">
                        <Border Background="{TemplateBinding Background}"
                                x:Name="border"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              Margin="{TemplateBinding Padding}"
                                              RecognizesAccessKey="True"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              FocusVisualStyle="{TemplateBinding FocusVisualStyle}" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled"
                                     Value="false">
                                <Setter Property="Foreground"
                                        Value="#ADADAD" />
                            </Trigger>
                            <Trigger Property="IsMouseOver"
                                     Value="True">
                                <Setter Property="Background"
                                        TargetName="border"
                                        Value="{Binding MouseOverBackground, RelativeSource={RelativeSource TemplatedParent}}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
     1  public class ImageButton : Button
     2     {
     3         static ImageButton()
     4         {
     5             DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(typeof(ImageButton)));
     6         }
     7 
     8         public Brush MouseOverBackground
     9         {
    10             get { return (Brush)GetValue(MouseOverBackgroundProperty); }
    11             set { SetValue(MouseOverBackgroundProperty, value); }
    12         }
    13 
    14 
    15         // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
    16         public static readonly DependencyProperty MouseOverBackgroundProperty =
    17             DependencyProperty.Register("MouseOverBackground", typeof(Brush), typeof(ImageButton), new PropertyMetadata(Brushes.Transparent));
    18     }
  • 相关阅读:
    J2EE技术(一)——JNDI
    软考注定是一次伤痛
    Ultraedit使用技巧收集
    ArcGIS Server Java 自定义Functionality(转)
    用C#动态刷新KML
    ArcGIS Server Java 自定义task
    Python动态刷新kml
    投影坐标知识小结
    tomcat配置数据源通过JNDI访问mysql数据库
    ArcGIS Server Java自定义tool
  • 原文地址:https://www.cnblogs.com/ligl/p/6700921.html
Copyright © 2011-2022 走看看