c# – WPF TextBlock文本绑定

c# – WPF TextBlock文本绑定,第1张

概述TextBlock绑定不起作用,我不知道为什么…… (此代码有效,但TextBlock未更新) XAML <TextBlock x:Name="filterAllText" Text="{Binding UpdateSourceTrigger=PropertyChanged}" /> 代码隐藏 filterAllText.DataContext = LogSession.test.MyCoynt 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;
总结

以上是内存溢出为你收集整理的c# – WPF TextBlock文本绑定全部内容,希望文章能够帮你解决c# – WPF TextBlock文本绑定所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1263229.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-08
下一篇2022-06-08

发表评论

登录后才能评论

评论列表(0条)

    保存