C# |
您所在的位置:网站首页 › 本地生活服务平台的盈利点 › C# |
源码打包下载 WPF功能强大,但是控件的用法与Winfrom不大一样。这个文件主要说明了Button控件的用法。希望能给大家一个启示。 1、按钮加入图片 图片的处理: 准备素材打开Properties\Resources.resx,添加素材属性的生成操作:Resources引用:2、窗体的xaml文件中直接使用模板 3、使用样式 App.xaml中定义样式 提示:x:Key="ButtonLeft" 就是 Style="{StaticResource ButtonLeft}" 样式名称 4、鼠标覆盖变淡 样式: 5、三态按钮及阴影效果 6、三态按钮及背景色、文字颜色变化 样式: 提示:TemplateBinding用来实现引用时给控件复制 如: Text="{TemplateBinding Content}",使用:Content="确定" FontSize="{TemplateBinding FontSize}" 使用:FontSize="18" 7、自定义控件 (1)解决方案→添加新建项→自定义控件(WPF) (2)CustomControl.cs using System; …… using Button = System.Windows.Controls.Button; namespace StudentImages { public class CustomControl : Button { static CustomControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl), new FrameworkPropertyMetadata(typeof(CustomControl))); } public ImageSource Icon { get { return (ImageSource)GetValue(IconProperty); } set { SetValue(IconProperty, value); } } public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(ImageSource), typeof(CustomControl), null); ………… } }说明: namespace StudentImages 命名空间,自动生成 public class CustomControl : Button CustomControl控件名称,自动生成 Button是继承的类,这里手工修改,否则这个自定义控件将会没有按钮的一些属性、事件 Icon是属性的名称 ImageSource是属性的类型 (3)Themes\Generic.xaml {TemplateBinding xxx} xxx:如果是原属性,这里直接使用;如果是自定义的,需要在cs文件中注册 源码打包下载 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |