嗨,我有一个INotifyPropertyChanged属性,而我想为该属性设置一个值,我得到了null引用异常,为什么会这样?我该如何解决这个问题?我需要在静态类中使用此属性,所以我已经创建了像这样的HolidayTool类
namespace Microsoft.Windows.Controls
{
public class Calendar : Control
{
public Calendar()
{
HolidayTool.HolidayTool.holy.HolidyContent = "test";
}
}
}
namespace HolidayTool
{
public class HolidayTool : INotifyPropertyChanged
{
internal static HolidayTool holy;
public event PropertyChangedEventHandler PropertyChanged;
public HolidayTool()
{
holy = this;
}
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string _HolidyContent;
public string HolidyContent
{
get => _HolidyContent;
set
{
if (value != _HolidyContent)
{
_HolidyContent = value;
OnPropertyChanged("HolidyContent");
}
}
}
}
}