1. <Style TargetType="{x:Type local:ImageButton}">
  2. <Setter Property="HorizontalContentAlignment"
  3. Value="Center"></Setter>
  4. <Setter Property="VerticalContentAlignment"
  5. Value="Center"></Setter>
  6. <Setter Property="Foreground"
  7. Value="White"></Setter>
  8. <Setter Property="Template">
  9. <Setter.Value>
  10. <ControlTemplate TargetType="{x:Type local:ImageButton}">
  11. <Border Background="{TemplateBinding Background}"
  12. x:Name="border"
  13. BorderBrush="{TemplateBinding BorderBrush}"
  14. BorderThickness="{TemplateBinding BorderThickness}">
  15. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  16. Margin="{TemplateBinding Padding}"
  17. RecognizesAccessKey="True"
  18. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  19. FocusVisualStyle="{TemplateBinding FocusVisualStyle}" />
  20. </Border>
  21. <ControlTemplate.Triggers>
  22. <Trigger Property="IsEnabled"
  23. Value="false">
  24. <Setter Property="Foreground"
  25. Value="#ADADAD" />
  26. </Trigger>
  27. <Trigger Property="IsMouseOver"
  28. Value="True">
  29. <Setter Property="Background"
  30. TargetName="border"
  31. Value="{Binding MouseOverBackground, RelativeSource={RelativeSource TemplatedParent}}" />
  32. </Trigger>
  33. </ControlTemplate.Triggers>
  34. </ControlTemplate>
  35. </Setter.Value>
  36. </Setter>
  37. </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. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  15. public static readonly DependencyProperty MouseOverBackgroundProperty =
  16. DependencyProperty.Register("MouseOverBackground", typeof(Brush), typeof(ImageButton), new PropertyMetadata(Brushes.Transparent));
  17. }

WPF Style Setter use a TemplateBinding?的更多相关文章

  1. WPF Style和Template

    WPF中的Style类似于Web应用程序中的CSS,它是控件的一个属性,属于资源的一种. ControlTemplate和DataTemplate区别: ControlTemplate用于改变控件原来 ...

  2. Bootstrap WPF Style(二)--Glyphicons 字体图标

    介绍 关于Glyphicons字体图标,首先给出友情链接 Glyphicons 这个项目是在Bootstrap WPF Style项目基础上做的,详见http://www.cnblogs.com/ts ...

  3. WPF Style设置和模板化Template

    WPF样式设置和模板化是一套功能(样式,模板,触发器和演示图版),可以为产品设置统一外观.类似于html的css,可以快速的设置一系列属性值到控件. 案例:ButtonStyle 这里创建了一个目标类 ...

  4. WPF Style

      <Application x:Class="WzlyTool.App" xmlns="http://schemas.microsoft.com/winfx/20 ...

  5. WPF style 换肤

    原文地址:http://www.cnblogs.com/DebugLZQ/p/3181040.html 原作者:DebugLZQ UI的风格一致性是应用程序应当关注的重要特性. 1.Creating ...

  6. Bootstrap WPF Style,Bootstrap风格的WPF样式

    简介 GitHub地址:https://github.com/ptddqr/bootstrap-wpf-style 此样式基于bootstrap-3.3.0,样式文件里的源码行数都是指的这个版本.CS ...

  7. WPF:在ControlTemplate中使用TemplateBinding

    A bit on TemplateBinding and how to use it inside a ControlTemplate. Introductio Today I'll try to w ...

  8. C#工具:Bootstrap WPF Style,Bootstrap风格的WPF样式

    简介 GitHub地址:https://github.com/ptddqr/bootstrap-wpf-style 此样式基于bootstrap-3.3.0,样式文件里的源码行数都是指的这个版本.CS ...

  9. wpf Style也继承(包含内部定义事件)

    如何在既定皮肤下为某个style添加内容是我今天碰的问题,皮肤往往是对全局control进行设置的,当然这就无法满足某个个性十足的“另类”了,比如当使用DataGridCheckBoxColumn时, ...

随机推荐

  1. Git 初始化全局user.name 和 user.email

    git config --global user.name "username" git config --global user.email "email"

  2. Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array 【dp】

    传送门:http://codeforces.com/contest/1105/problem/C C. Ayoub and Lost Array time limit per test 1 secon ...

  3. (第二场)D Money 【dp\贪心】

    题目:https://www.nowcoder.com/acm/contest/140/D 题目描述: White Cloud has built n stores numbered from 1 t ...

  4. MVC 实现下拉框

    MVC动态实现下拉框的方式有很多种,但是方便快捷的却是很少,现在记录一种常用的下拉框实现方式: 1.先看看视图代码是怎么写的 <div class="form-group col-xs ...

  5. Objective-C中,ARC下的 strong和weak指针原理解释

    Objective-C中,ARC下的 strong和weak指针原理解释 提示:本文中所说的"实例变量"即是"成员变量","局部变量"即是& ...

  6. webservice 从客户端中检测到有潜在危险的 Request.Form 值

    webservice中传递xml格式的参数时报错 webservice 从客户端中检测到有潜在危险的 Request.Form 值解决方案: 1.在web.config的system.web节点中添加 ...

  7. oracle之DQL

    一.单表查询 语法:select * from table where 条件 group by 分组 having 过滤分组 order by 排序 --查询平均工资低于2000的部门的最大工资和平均 ...

  8. 自定义UICollectionViewLayout并添加UIDynamic

    大家也可以到这里查看. UICollectionView是iOS6引入的控件,而UIDynamicAnimator是iOS7上新添加的框架.本文主要涵盖3部分: 一是简单概括UICollectionV ...

  9. eclipse安装tomcat时只有locahost,不显示server name

    Eclipseh中无法安装Tomcat,报错信息如下 Cannot create a server using the selected type   原因:以前安装的tomcat目录改变 解决方法: ...

  10. Xdebug 备注

    安装步骤: 查看自己的环境是否已安装 Xdebug ,查看方法:使用phpinfo(),搜索 Xdebug 如果没有 如图: 如果没有:下一步确定你的PHP版本信息: Xdebug下载地址 https ...