WPF自定义控件
来源:互联网 发布:好听音乐网络歌曲 编辑:程序博客网 时间:2024/05/21 10:15
using System.Windows;using System.Windows.Controls;using System.Windows.Media;namespace ZJWMSUI.Controls{ public class DazzleButton : Button { public static readonly DependencyProperty MyMoverBrushProperty; public static readonly DependencyProperty MyEnterBrushProperty; public Brush MyMoverBrush { get { return base.GetValue(DazzleButton.MyMoverBrushProperty) as Brush; } set { base.SetValue(DazzleButton.MyMoverBrushProperty, value); } } public Brush MyEnterBrush { get { return base.GetValue(DazzleButton.MyEnterBrushProperty) as Brush; } set { base.SetValue(DazzleButton.MyEnterBrushProperty, value); } } static DazzleButton() { DazzleButton.MyMoverBrushProperty = DependencyProperty.Register("MyMoverBrush", typeof(Brush), typeof(DazzleButton), new PropertyMetadata(null)); DazzleButton.MyEnterBrushProperty = DependencyProperty.Register("MyEnterBrush", typeof(Brush), typeof(DazzleButton), new PropertyMetadata(null)); FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(DazzleButton), new FrameworkPropertyMetadata(typeof(DazzleButton))); } public DazzleButton() { base.Content = ""; base.Background = Brushes.Orange; } }}
using System.Windows;using System.Windows.Controls;using System.Windows.Media;using System.ComponentModel;namespace ZJWMSUI.Controls{ public class XButton : Button { static XButton() { DefaultStyleKeyProperty.OverrideMetadata(typeof(XButton), new FrameworkPropertyMetadata(typeof(XButton))); var metadata = new FrameworkPropertyMetadata((ImageSource)null); ImageSourceProperty = DependencyProperty.RegisterAttached("ImageSource", typeof(ImageSource), typeof(Button), metadata); } #region 属性 public ImageSource ImageSource { get { return (ImageSource)GetValue(ImageSourceProperty); } set { SetValue(ImageSourceProperty, value); } } public static DependencyProperty ImageSourceProperty; #endregion #region 隐藏基类属性 [Browsable(false)] public new Brush Background { get { return base.Background; } set { base.Background = value; } } [Browsable(false)] public new Brush BorderBrush { get { return base.BorderBrush; } set { base.BorderBrush = value; } } #endregion }}
using System.Windows;using System.Windows.Controls;using System.Windows.Media;using System.ComponentModel;namespace ZJWMSUI.Controls{ /// <summary> /// 按照步骤 1a 或 1b 操作,然后执行步骤 2 以在 XAML 文件中使用此自定义控件。 /// /// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。 /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 /// 元素中: /// /// xmlns:MyNamespace="clr-namespace:WpfApplication3" /// /// /// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。 /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 /// 元素中: /// /// xmlns:MyNamespace="clr-namespace:WpfApplication3;assembly=WpfApplication3" /// /// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用, /// 并重新生成以避免编译错误: /// /// 在解决方案资源管理器中右击目标项目,然后依次单击 /// “添加引用”->“项目”->[浏览查找并选择此项目] /// /// /// 步骤 2) /// 继续操作并在 XAML 文件中使用控件。 /// /// <MyNamespace:XTextBox/> /// /// </summary> public class XTextBox : TextBox { static XTextBox() { DefaultStyleKeyProperty.OverrideMetadata(typeof(XTextBox), new FrameworkPropertyMetadata(typeof(XTextBox))); var metadata = new FrameworkPropertyMetadata((ImageSource)null); ImageSourceProperty = DependencyProperty.RegisterAttached("ImageSource", typeof(ImageSource), typeof(TextBox), metadata); var metadata1 = new FrameworkPropertyMetadata((string)""); XTextBox.ContentTextProperty = DependencyProperty.RegisterAttached("ContentText", typeof(string), typeof(TextBox), metadata1); } public ImageSource ImageSource { get { return (ImageSource)GetValue(ImageSourceProperty); } set { SetValue(ImageSourceProperty, value); } } public static readonly DependencyProperty ImageSourceProperty; public string ContentText { get { return (string)GetValue(ContentTextProperty); } set { SetValue(ContentTextProperty, value); } } public static readonly DependencyProperty ContentTextProperty; #region 隐藏基类属性 [Browsable(false)] public new Brush Background { get { return base.Background; } set { base.Background = value; } } [Browsable(false)] public new Brush BorderBrush { get { return base.BorderBrush; } set { base.BorderBrush = value; } } #endregion }}
0 0
- WPF自定义控件
- WPF自定义控件选择
- WPF自定义控件
- WPF中自定义控件
- WPF自定义控件
- WPF中自定义控件
- WPF之自定义控件
- WPF 自定义控件
- WPF 自定义控件类型
- wpf自定义控件位置
- WPF自定义控件
- wpf自定义计时器控件
- WPF自定义分页控件
- WPF自定义搜索控件
- 在WPF中自定义控件
- wpf --自定义控件的transeform
- WPF 继承自定义的控件
- WPF 自定义控件不能不服
- 二叉树的基本用法总结
- 算法学习笔记之图解冒泡法
- java并发等待条件的实现原理(Condition)
- Web响应式设计(一)
- oracle归档日志清理
- WPF自定义控件
- 包干到户是最好的软件项目管理方法
- ping: unknown host www.baidu.com解决
- JAVA中通过JNI调用C程序实例教程
- 7.13 BHDU 3671 Boonie and Clyde
- 指针铁律1:指针也是一种数据类型
- IT行业岗位以及发展方向(职业规划迷茫的欢迎查看)
- java中的位运算符
- MyEclipse2016CI6破解方法