我目前正在尝试新编译的绑定,并且已经达到(再次)我错过了一个难题的一个点:为什么我必须打电话Bindings.Update?到现在为止,我认为实施 INotifyPropertyChanged已经足够了?
在我的例子中,如果我调用这个神秘的方法(由编译的绑定自动生成),GUI只显示正确的值.
我正在使用具有以下(此处简化的)xaml语法的用户控件:
<UserControl>
<TextBlock Text="x:Bind TextValue"/>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
where TextValue是此用户控件的简单依赖项属性.在页面中,我将此控件用作:
<Page>
<SampleControl TextValue="{x:Bind ViewModel.Instance.Name}"/>
</Page>
Run Code Online (Sandbox Code Playgroud)
哪里:
ViewModel是一个在InitializeComponent()运行之前设置的标准属性Instance 是一个简单的实现对象 INotifyPropertyChanged加载后Instance,我提出了一个属性更改事件Instance.我甚至可以调试到TextValue用户控件的depency属性获取正确值的行 - 但是没有显示任何内容.只有在我打电话时Bindings.Update(),才会显示该值.我在这里错过了什么?
更新
我也没办法{x:Bind ... Mode=OneWay}.
更多代码
Person.cs:
using System.ComponentModel;
using System.Threading.Tasks;
namespace App1 {
public class Person : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
private string name;
public string Name { get {
return this.name;
}
set …Run Code Online (Sandbox Code Playgroud)