• 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>
  • 相关阅读:
    linux文件权限查看及修改(实用)
    将JSON对象带有格式的写出到文件中
    mySQL数据库Sql语句执行效率检查--Explain命令
    mysql优化
    Linux-设置固定IP
    logback 配置详解(二)——appender
    logback 配置详解(一)——logger、root
    Thread
    Singleton
    多线程编程总结
  • 原文地址:https://www.cnblogs.com/kybs0/p/5812174.html
Copyright © 2020-2023  润新知