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以上才有这个功能,