标签:
用于记录自己的学习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 }
以上属性都比较简单,就只简单介绍下,在我们自绘控件时知道有这些属性就好了。
标签:
原文地址:http://www.cnblogs.com/chensheng808/p/4673157.html