【问题标题】:How to bind a TextBox to a Class如何将文本框绑定到类
【发布时间】:2020-01-03 03:45:27
【问题描述】:

如何将一个页面上 TextBox 中的文本绑定到另一个页面上的全局类?

我当前的代码:

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 时,类中的值仍然为 null 并且不会更新。

  1. 我是否正确绑定了值?

  2. 如果是这样,我如何让课程更新?

编辑:

  1. 是的,我已经正确绑定了

  2. 我所要做的就是添加属性Mode=TwoWay, UpdateSourceTrigger=PropertyChanged

解决方案:

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

【问题讨论】:

标签: c# uwp binding textbox


【解决方案1】:
  1. 是的,绑定正确

  2. 您所要做的就是使用属性Mode=TwoWay, UpdateSourceTrigger=PropertyChanged

解决方案:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2023-04-06
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    相关资源
    最近更新 更多