zoukankan      html  css  js  c++  java
  • 自定义事件、属性、方法

    首先自定义事件:

    public class DropdownTextBox : Control
        {
        public static readonly RoutedEvent DropdownOpenedEvent = EventManager.RegisterRoutedEvent("DropdownOpened", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(DropdownTextBox));  // 事件系统注册新的路由事件。
         //类型也可以改为RoutedEventHandler   事件名称,事件传阅的方式(向上传阅,向下传阅或不传阅),事件对应的EventHandler的类型,事件拥有者的类型)
    public event TextChangedEventHandler TextChanged { add { AddHandler(TextChangedEvent, value); } remove { RemoveHandler(TextChangedEvent, value); } } } 
    public static readonly DependencyProperty TextProperty = TextBox.TextProperty.AddOwner(typeof(DropdownTextBox),new FrameworkPropertyMetadata(new PropertyChangedCallback(TextPropertyChanged)));
       
            private static void TextPropertyChanged(DependencyObject d, DependencyPropertyChangedEve
        //参数属性名(该属性名与声明的依赖属性名称"XXXProperty"相比仅仅是少了"Property"后缀,其它完全一样,否则在运行时会报异常),属性的数据类型,属性的拥有者的类型,元数据.
    ntArgs e) { DropdownTextBox db = d as DropdownTextBox; db.OnTextChanged(); } /// <summary> /// 获取或设置控件中显示的文本 /// </summary> public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } }
       protected virtual void OnTextChanged()
            {
                RoutedEventArgs args = new RoutedEventArgs(TextChangedEvent, this);
                RaiseEvent(args);
            }

    // 有待整理。。。。。。

    参考资料 http://www.cnblogs.com/zhouyinhui/archive/2007/10/27/939920.html

  • 相关阅读:
    C#中怎么设置comboBox1为只读,即不可在里面进行编辑?
    笔记
    Head First ObjectOriented Analysis & Design 读书 概记
    看到这篇东西 ,要收藏 呵呵
    HELLO OPENGL
    调试opengl程序出错
    HeadFirst C# 读书笔记 0426
    css布局容易范的一些错误
    百度新年贪吃蛇效果
    css3教程:boxsizing属性说明
  • 原文地址:https://www.cnblogs.com/wlwenjie/p/4497380.html
Copyright © 2011-2022 走看看