WPF TextBlock 文本绑定绑定、文本、WPF、TextBlock

由网友(毕业那天都不许哭)分享简介:TextBlock 绑定不起作用,我不知道为什么...... the TextBlock binding does not work and I cant figure why... (此代码有效,但 TextBlock 未更新)(This Code Works but the TextBlock does no...

TextBlock 绑定不起作用,我不知道为什么......

the TextBlock binding does not work and I cant figure why...

(此代码有效,但 TextBlock 未更新)

(This Code Works but the TextBlock does not get Updated )

XAML

<TextBlock x:Name="filterAllText"
 Text="{Binding UpdateSourceTrigger=PropertyChanged}" />

代码隐藏

filterAllText.DataContext = LogSession.test.MyCoynt;

C#

public class Test : INotifyPropertyChanged {
 public int myCoynt;

     public int MyCoynt {
        get { return myCoynt; }
        set {
            myCoynt = value;
            NotifyPropertyChanged();
        }
    }

     public event PropertyChangedEventHandler PropertyChanged;

     protected virtual void NotifyPropertyChanged(
        [CallerMemberName] String propertyName = "") {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null) {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
}

推荐答案

试试这个:

<TextBlock x:Name="filterAllText" 
    Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=MyCoynt}" />

并将您的 DataContext 设置为:

filterAllText.DataContext = LogSession.test;
阅读全文

相关推荐

最新文章