如何将 TextBox 绑定到 Class
How to bind a TextBox to a Class
我如何将一页 TextBox
中的文本绑定到另一页的全局 class?
我当前的代码:
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}
没有抛出任何错误,但是当我输入 TextBox
时,class 中的值仍然为空并且不会更新。
我是否正确绑定了值?
如果是这样,我如何让 class 更新?
编辑:
是的我绑定正确了
我所要做的就是添加属性 Mode=TwoWay, UpdateSourceTrigger=PropertyChanged
解法:
{x:Bind Path=local:App.customer.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}
是的,绑定正确
您所要做的就是使用属性 Mode=TwoWay, UpdateSourceTrigger=PropertyChanged
解法:
{x:Bind Path=local:App.customer.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}
我如何将一页 TextBox
中的文本绑定到另一页的全局 class?
我当前的代码:
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}
没有抛出任何错误,但是当我输入 TextBox
时,class 中的值仍然为空并且不会更新。
我是否正确绑定了值?
如果是这样,我如何让 class 更新?
编辑:
是的我绑定正确了
我所要做的就是添加属性
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged
解法:
{x:Bind Path=local:App.customer.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}
是的,绑定正确
您所要做的就是使用属性
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged
解法:
{x:Bind Path=local:App.customer.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}