WPF binding not updating the view

WPF binding not updating the view

 

回答1

You need to implement INotifyPropertyChanged in your ViewModel order to notify the View that the property has changed.

Here's a link to the MSDN page for it: System.ComponentModel.INotifyPropertyChanged

The most important thing to note is that you should raise the PropertyChanged event in your property setter.

 

回答2

Add binding mode two way, because by default Textblock's binding mode is one way

<TextBlock HorizontalAlignment="Left" Name="StatusText" Margin="0,20" TextWrapping="Wrap" Text="{Binding StatusText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            ... Status ...
</TextBlock>

and also, of course you need to implement INotifyPropertyChanged for the purpose, refer to this link for how to implement.

评论

Making the binding twoway is pointless as the control can't change the text so has no need to be able to update the source. Oct 20, 2015 at 11:00

 

回答3

Your view model needs to implement INotifyPropertyChanged, and you need to raise it every time one of your property changes (ie in the setter).

Without it WPF has no way of knowing that the property has changed.

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-09-09 export datatable to csv
2020-09-09 How to send Ajax request, using HttpClient
2015-09-09 git stash的使用
点击右上角即可分享
微信分享提示