“UpdateSourceTrigger=PropertyChanged” equivalent for a TextBox in WinRT-XAML

南楼画角 提交于 2019-11-28 21:36:00
Luke Puplett

It seems UpdateSourceTrigger and GetBindingExpression are available in Windows 8.1. Thanks to Rico Suter above and HDW Production from this question:

Windows Store TextBox - How to update binding on Enter key-up?

Jerry,

The pattern that you should use would be implementing INotifyPropertyChanged. Heres and example from MSDN: http://msdn.microsoft.com/en-us/library/ms229614.aspx

In this way, any XAML object that is bound to a backing property or field, will be notified when the backing field's value has changed, because of the call to the NotifyPropertyChanged() method.

If you were to implement this pattern you wouldnt need to explicitly define when to update the UI, all UI elelments that are bound to Notifyable propertied will as you're expecting Update when the Source Changes.

For Classes that Implement INotifyPropertyChanged

I use a snippet to create most of my properties like this (if there is any chance they will be bound or will need to notify another object):

private PropertyChangedEventArgs myVarChangedEventArgs = new PropertyChangedEventArgs("MyProperty");
private int myVar;
public int MyProperty
{
get { return myVar; }
set
  {
     if (myVar != value)
     {
        myVar = value;
        NotifyPropertyChanged(myVarChangedEventArgs);
      }
   }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!