zoukankan      html  css  js  c++  java
  • TemplatePart特性的作用

    看wp控件的源代码时发现TemplatePart特性,于是在百度上查了查: 

    http://blog.csdn.net/wushang923/article/details/9224533 

    TemplatePart(Name="PART_Decrease", Type=typeof(RepeatButton))

    一直没明白这是干嘛用的,搜了一下,记载一下。

    以Button的定义为例:

    namespace System.Windows.Controls
    {
        // Summary:
        //     Represents a button control, which reacts to the Click event.
        [TemplatePart(Name = "Normal State", Type = typeof(Storyboard))]
        [TemplatePart(Name = "MouseOver State", Type = typeof(Storyboard))]
        [TemplatePart(Name = "RootElement", Type = typeof(FrameworkElement))]
        [TemplatePart(Name = "Pressed State", Type = typeof(Storyboard))]
        [TemplatePart(Name = "FocusVisualElement", Type = typeof(UIElement))]
        [TemplatePart(Name = "Disabled State", Type = typeof(Storyboard))]
        public class Button : ButtonBase
        {
            // Summary:
            //     Initializes a new instance of the Button class.
            public Button();
            // Summary:
            //     Apply a template to the Button.
            protected override void OnApplyTemplate();
            //
            // Summary:
            //     Called when the IsEnabled property changes.
            //
            // Parameters:
            //   isEnabled:
            //     New value of the IsEnabled property.
            protected override void OnIsEnabledChanged(bool isEnabled);
        }
    }
    

      [TemplatePart(Name = "Normal State", Type = typeof(Storyboard))] 这种东东是做什么用的 , 其实这是一种契约 , 是一种推荐的控件设计模式(只是推荐) , 意思是告诉要来写ControlTemplate的用户 , 你的ControlTemplate中需要有一个x:Name为“Normal State” , 类型为Storyboard , 当然这个类型可以是继承来的, 为什么一定要包含这些契约规定的元素 , 因为逻辑部分对这些东西进行了引用,它们将对控件的默认行为起着关键作用, 可以理解为这个控件的最基本元素 , 是实现默认行为的最小集合, 自然,你的ControlTemplate中如果没有包含契约中的内容 , 则相应的逻辑将无法实现。

    所以说白了,就是提示用的.....这么写比较规范。

  • 相关阅读:
    STL的二分查找binary_search
    转_HDU_1907&2509 博弈(Nim博弈变形)
    HDU3589_Jacobi symbol_二次剩余
    转载_模运算_归纳得很精华啊
    HDU3501_calculation2_欧拉函数求和
    【转】求小于等于N的与N互质的数的和
    HDU3328_Flipper_纸牌翻转_模拟题
    转_求逆元的两种方法
    HDU2541_Simple Addition Expression
    MySql数据同步(双机热备)已正式应用上平台
  • 原文地址:https://www.cnblogs.com/poison/p/3540159.html
Copyright © 2011-2022 走看看