繁体   English   中英

通知属性更改不起作用

[英]Notify Property Changed not working

这是我的xml代码

<TextBlock Grid.Column="0" Tag="{Binding id,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Text="{Binding Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>

这是我的模特

public string _Name;
public string Name
{
    get { return _Name; }
    set { _Name = value; RaisePropertyChanged("Name"); }
}      

当我设置这两个属性的价值,即。 到ID和名称

但它通知名称...

具有更新的简单数据绑定示例。 您可以以此为参考入门:)

public partial class MainWindow : Window, INotifyPropertyChanged
{
    // implement the INotify
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    private string _mytext;
    public String MyText
    {
        get { return _mytext;  }
        set { _mytext = value; NotifyPropertyChanged("MyText"); }
    }

    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = this;             // set the datacontext to itself :)
        MyText = "Change Me";
    }
}

<TextBlock Text="{Binding MyText}" Foreground="White" Background="Black"></TextBlock>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM