1

I have below property in my MainPage. And i am am trying to bind this to a TextBox in the xaml file.

property String^ TestProperty
{
 String^ get() { return m_testItem; };
 void set(String^ val) { m_testItem= val; }
}

xaml code :

<TextBox Grid.Row="1" Grid.Column="0" x:Name="testVal" x:Uid="testVal" Header="Laser" Text="{x:Bind TestProperty, Mode=TwoWay}"/>

I Can not see any value in the control. What am i missing here?

sohel14_cse_ju
  • 2,481
  • 9
  • 34
  • 55
  • Look at the Output window, you may find error message that TestProperty is not resolved. Did you forget to set the DataContext object? Something like this.DataContext = this; in MainPage’s constructor. – kennyzx May 05 '19 at 07:38
  • Does this answer help ? https://stackoverflow.com/a/55438146/7325217 – Pratyay May 05 '19 at 15:03

1 Answers1

1

I Can not see any value in the control. What am i missing here?

You just declare TestProperty but you have not valued it. You could get TestProperty value in the MainPage construct method.

MainPage::MainPage()
{
    InitializeComponent();  
    TestProperty = "HelloW";
}

I found you used Mode=TwoWay, So you need implement INotifyPropertyChanged interface. For more detail steps please refer data-binding-in-depth

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36