WPF控件自绘——基础,Control类的定义

用于记录自己的学习WPF控件,大神请飘过。。。

【WPF控件类继承关系图】 

所有可以自定义模版的控件都是从Control继承,所以我们来看看Contorl类里面到底有些什么。为以后的控件自定义模版做好准备。废话少说先来看看WPF中Control类的定义

 1 namespace System.Windows.Controls
 2 {
 3   public class Control : FrameworkElement
 4   {
 5     public static readonly DependencyProperty BorderBrushProperty;    
 6     public static readonly DependencyProperty BorderThicknessProperty; 
 7     public static readonly DependencyProperty BackgroundProperty;      
 8     public static readonly DependencyProperty ForegroundProperty;      
 9     public static readonly DependencyProperty FontFamilyProperty;      
10     public static readonly DependencyProperty FontSizeProperty;        
11     public static readonly DependencyProperty FontStretchProperty;     
12     public static readonly DependencyProperty FontStyleProperty;       
13     public static readonly DependencyProperty FontWeightProperty;
14     public static readonly DependencyProperty HorizontalContentAlignmentProperty;
15     public static readonly DependencyProperty VerticalContentAlignmentProperty;
16     public static readonly DependencyProperty TabIndexProperty;
17     public static readonly DependencyProperty IsTabStopProperty;
18     public static readonly DependencyProperty PaddingProperty;
19     public static readonly DependencyProperty TemplateProperty;
//以上为依赖属性的定义,主要看下面的这些属性和方法
20 public static readonly RoutedEvent PreviewMouseDoubleClickEvent; 21 public static readonly RoutedEvent MouseDoubleClickEvent;
//以上两个为路由事件
22 public Control();
//模版发生改变时调用此事件
23 protected virtual void OnTemplateChanged(ControlTemplate oldTemplate, ControlTemplate newTemplate); 24 public override string ToString(); 25 protected virtual void OnPreviewMouseDoubleClick(MouseButtonEventArgs e); 26 protected virtual void OnMouseDoubleClick(MouseButtonEventArgs e); 27 protected override Size MeasureOverride(Size constraint); 28 protected override Size ArrangeOverride(Size arrangeBounds); 29 [Bindable(true)] 30 [Category("Appearance")] 31 public Brush BorderBrush { get; set; } //边框颜色画刷 32 [Bindable(true)] 33 [Category("Appearance")] 34 public Thickness BorderThickness { get; set; } //边框大小 35 [Bindable(true)] 36 [Category("Appearance")] 37 public Brush Background { get; set; } //背景颜色 38 [Category("Appearance")] 39 [Bindable(true)] 40 public Brush Foreground { get; set; } //前景颜色 41 [Bindable(true)] 42 [Category("Appearance")] 43 [Localizability(LocalizationCategory.Font)] 44 public FontFamily FontFamily { get; set; } //字体 45 [Category("Appearance")] 46 [Localizability(LocalizationCategory.None)] 47 [TypeConverter(typeof (FontSizeConverter))] 48 [Bindable(true)] 49 public double FontSize { get; set; } //字体大小 50 [Bindable(true)] 51 [Category("Appearance")] 52 public FontStretch FontStretch { get; set; } //字体拉伸描述字体形状从其普通纵横比拉伸的程度,普通纵横比是为字体中的标志符号指定的宽度与高度的原始比例。 53 [Bindable(true)] 54 [Category("Appearance")] 55 public FontStyle FontStyle { get; set; } //字体风格 ,设置字体的倾斜特性 56 [Category("Appearance")] 57 [Bindable(true)] 58 public FontWeight FontWeight { get; set; } //字体加粗效果 59 [Category("Layout")] 60 [Bindable(true)] 61 public HorizontalAlignment HorizontalContentAlignment { get; set; } //这个属性用来设置该控件相对父控件的横向摆放位置,而不是控件内的内容的摆放位置 62 [Bindable(true)] 63 [Category("Layout")] 64 public VerticalAlignment VerticalContentAlignment { get; set; } 65 [Category("Behavior")] 66 [Bindable(true)] 67 public int TabIndex { get; set; } //支持Tab键切换焦点,用来设置tab键切换的顺序 68 [Category("Behavior")] 69 [Bindable(true)] 70 public bool IsTabStop { get; set; } //用来控制是否接受tab键的焦点切换 71 [Category("Layout")] 72 [Bindable(true)] 73 public Thickness Padding { get; set; } //控件内的内容与控件的边界的间距
//模版属性,后面在自绘控件时再详细介绍。
74 public ControlTemplate Template { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; } 75 protected internal virtual bool HandlesScrolling { get; } //获取一个值,该值指示组合框是否支持滚动。 76 public event MouseButtonEventHandler PreviewMouseDoubleClick; 77 public event MouseButtonEventHandler MouseDoubleClick; 78 } 79 }

以上属性都比较简单,就只简单介绍下,在我们自绘控件时知道有这些属性就好了。

转载于:https://www.cnblogs.com/chensheng808/p/4673157.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WPF(Windows Presentation Foundation)是一个用于构建Windows应用程序的框架,而UserControlWPF的一种自定义控件。 UserControl允许我们将多个现有的WPF控件组合在一起,形成一个新的、可重用的控件。通过创建自定义的UserControl,我们可以将一组相关的控件封装成一个单一的控件,以增强应用程序的可维护性和重用性。 创建自定义的UserControl通常有以下几个步骤: 1. 创建一个新的WPF用户控件项目,并定义UserControl的外观和布局。这可以通过在XAML文件使用已有的WPF控件、布局容器和样式来完成。 2. 在UserControl的代码后台(Code-behind)文件,可以定义一些附加的属性和方法,以增强UserControl的可定制性和功能。 3. 在UserControl可以定义一些依赖属性(Dependency Properties),以允许开发者在使用UserControl时进行数据绑定和属性设置。 4. 在需要使用自定义UserControl的地方,可以将其直接添加到XAML,并进行相关的属性设置和事件处理。 自定义的UserControl可以在整个应用程序重复使用,从而提高了开发效率。通过UserControl的封装,我们可以将一组相关的功能和样式打包到单个控件,简化了应用程序的UI设计和代码开发过程。 总而言之,WPF的自定义控件UserControl为开发者提供了一种简单且高效的方式来自定义和组合现有的WPF控件,以创建出更具可重用性和可维护性的应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值