DavidSNB
DavidSNB

Reputation: 181

How to bind a TextBox to a Class

How would I go about binding the text in a TextBox on one page to a global class from another?

My current code:

App.xaml.cs

public static CustomerClass customer = new CustomerClass();

AddCustomer.xaml

<TextBox x:Name="txtLastName" PlaceholderText="Last name" 
         Text="{x:Bind Path=local:App.customer.LastName}"/>

{x:Bind Path=local:App.customer.LastName} isn't throwing any errors however when I type into the TextBox the value in the class remains null and doesn't update.

  1. Have I bound the values correctly?

  2. If so how do I get the class to update?

Edit:

  1. Yes I had bound it correctly

  2. All I had to do was add the properties Mode=TwoWay, UpdateSourceTrigger=PropertyChanged

Solution:

{x:Bind Path=local:App.customer.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}

Upvotes: 1

Views: 176

Answers (1)

DavidSNB
DavidSNB

Reputation: 181

  1. Yes it is bound correctly

  2. All you have to do is use the properties Mode=TwoWay, UpdateSourceTrigger=PropertyChanged

Solution:

{x:Bind Path=local:App.customer.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}

Upvotes: 1

Related Questions