c# – WPF TextBlock文本绑定

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

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

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;

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...