根据this instruction,我试图使用INotifyPropertyChanged函数来刷新我的UWP应用程序中的绑定数据。不幸的是,当数据的值从代码后面改变时,事件PropertyChangedEventHandler返回null值(PropertyChanged = null在检查这个陈述期间:if(PropertyChanged!= null))。当值从应用程序页面更改(通过输入值到文本框)PropertyChanged设置了一些值。UWP INotifyPropertyChanged为空(c#)
我的类INotifyPropertyChanged的:
public sealed partial class PartCreatePage : Page
{
private UserOperation operation { get; set; }
public PartCreatePage()
{
this.InitializeComponent();
operation = new UserOperation();
}
private void OperationAck_Button(object sender, RoutedEventArgs e)
{
operation.BeginDistance = 500;
}
和XAML:
public class UserOperation : INotifyPropertyChanged
{
private int _beginDistance, _endDistance;
public int BeginDistance {get { return _beginDistance; }
set
{
_beginDistance = value;
NotifyPropertyChanged("BeginDistance");
}
}
public int EndDistance { get { return _endDistance; }
set
{
_endDistance = value;
NotifyPropertyChanged("EndDistance");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
在后面的代码执行
<TextBox x:Name="begin_Distance"
Text="{x:Bind operation.BeginDistance, Mode=TwoWay}"
KeyDown="onlyNumeric_KeyDown"
Style="{StaticResource OperationFlyout_TextBox}" />
你是什么意思“事件PropertyChangedEventHandler返回空值”? –
这意味着:PropertyChanged = null在检查这个陈述期间:if(PropertyChanged!= null) – kristof43
检查是否有帮助。我有一个类似的问题:http://stackoverflow.com/questions/42354995/propertychanged-is-null-uwp – KonKarapas