zoukankan      html  css  js  c++  java
  • WPF 依赖属性

    依赖属性,简单的说,在WPF控件应用过程中,界面上直接可以引用的属性

    如:<Button Content="aaa"></Button>

    Content称为Button的依赖属性

    当我们自定义控件时,如何添加依赖属性呢

    1、添加属性

            /// <summary>
            /// get or set the items
            /// </summary>
            public List<TitleListItemModel> TitleListItems
            {
                get
                {
                    return (List<TitleListItemModel>) GetValue(TitleListItemsProperty)
                }
                set{SetValue(TitleListItemsProperty,value);};
            }

    2、注册属性

            public static readonly DependencyProperty TitleListItemsProperty = DependencyProperty.Register("TitleListItems", typeof(List<TitleListItemModel>),
                typeof(TitleListControl),new PropertyMetadata(new List<TitleListItemModel>()));

    然后在应用自定义控件时,就能直接设置属性了,例如:

    TitleListItems属性可以直接在界面上添加
            <wpfApplication6:TitleListControl VerticalAlignment="Center">
                <wpfApplication6:TitleListControl.TitleListItems>
                    <wpfApplication6:TitleListItemModel Name="AAA" Text="aa"></wpfApplication6:TitleListItemModel>
                    <wpfApplication6:TitleListItemModel Name="bb" Text="BB"></wpfApplication6:TitleListItemModel>
                    <wpfApplication6:TitleListItemModel Name="ccc" Text="CC"></wpfApplication6:TitleListItemModel>
                </wpfApplication6:TitleListControl.TitleListItems>
            </wpfApplication6:TitleListControl>
  • 相关阅读:
    Android 侧滑(双向滑动菜单)效果
    Android中PopupWindow中有输入框时无法弹出输入法的解决办法
    Android 调用图库选择图片实现和参数详解
    5.抽象类篇
    4.事件篇
    3.委托篇
    2.结构篇
    1.枚举篇
    读取excel到数据库里面
    Windows系统安装docker
  • 原文地址:https://www.cnblogs.com/kybs0/p/5812174.html
Copyright © 2011-2022 走看看