Universal Windows Platform (UWP)
A Microsoft platform for building and publishing apps for Windows desktop devices.
2,825 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I have a problem with x:bind, UI isnt notified when object is created.
I have such XAML:
<TextBox Text="{x:Bind myClass.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<Button Content="TEST" Click="Button_Click"></Button>
</StackPanel>
c#
namespace XBIND_test
{
public sealed partial class MainPage : Page
{
public MyClass myClass;
public MainPage()
{
this.InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
myClass = new MyClass();
}
}
public class MyClass : INotifyPropertyChanged
{
private string name = "AAAA";
public string Name
{
get { return name; }
set
{
name = value;
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
When UI is initialized myClass object is null. It will be created when user clicks button. After button is clicked, "AAAA" string should appear in the TextBox. How to code such functionality using x:bind?
Try an additional notification:
public sealed partial class MainPage : Page, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
. . .
private void Button_Click( object sender, RoutedEventArgs e )
{
myClass = new MyClass( );
PropertyChanged( this, new PropertyChangedEventArgs( nameof( myClass ) ) );
}
}