WPF 绑定到静态属性(4.5)

时间:2019-03-17 17:50:25   收藏:0   阅读:234

1. 声明静态事件

 

        /// <summary>
        /// 静态属性通知
        /// </summary>
        public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;

 

2.静态属性 setter

        private static bool _IsConnectSeccess;
        /// <summary>
        /// 是否连接成功
        /// </summary>
        public static bool IsConnectSeccess
        {
            get { return _IsConnectSeccess; }
            set
            {
                _IsConnectSeccess = value;
                StaticPropertyChanged?.Invoke(null,new PropertyChangedEventArgs(nameof(IsConnectSeccess)));
            }
        }

 

 

3. xmal    这里比较重要, 要加括号  不然不能正常通知  甚至编译时异常 T-T

        <Border Name="CommunicationStatuBorder" IsHitTestVisible="False" Background="{Binding Path=(siemens:SiemensConnection.IsConnectSeccess) ,UpdateSourceTrigger=PropertyChanged,ConverterParameter=‘false,#90FF0000 true,#00000000‘,Converter={StaticResource comct}}"/>

 

 

4.  只有.net frameWork 4.5以上才有这个功能, 

原文:https://www.cnblogs.com/nocanstillbb/p/10547960.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!