【发布时间】:2018-04-26 21:29:47
【问题描述】:
您好,我们将处理 OnPropertyChanged 事件并在所有应用程序表单中获取此变量的值。
using System;
using System.ComponentModel;
using System.Windows;
public partial class App : INotifyPropertyChanged
{
#region - Connected -
/// <summary>
/// Gets or sets Connected status
/// </summary>
private Boolean connected = false;
public Boolean Connected
{
get { return connected; }
set
{
if(connected != value)
{
connected = value;
OnPropertyChanged("Connected");
}
}
}
#endregion - Connected -
#region - INotifyPropertyChanged implementation -
// Basically, the UI thread subscribes to this event and update the binding if the received Property Name correspond to the Binding Path element
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion - INotifyPropertyChanged implementation -
}
如何触发此事件“OnPropertyChanged”并在所有 App 的窗口上获取 Connected 值。
【问题讨论】:
-
我不建议在这种情况下使用 on property change,您可能想创建自定义事件并订阅它。
标签: c# wpf code-behind