开发者

How to trigger binding source update from code in WPF?

开发者 https://www.devze.com 2022-12-30 20:10 出处:网络
In My ViewModel class I have a property: class ViewModel : INotifyPropertyChanged { public string FileName {get;set;}

In My ViewModel class I have a property:

class ViewModel : INotifyPropertyChanged
{
public string FileName {get;set;}
}

and in my View I bind a label's content to ViewModel's FileName.

now When I do drag-drop a file to my View, How can I update the label's Content property, so that the ViewMode's FileName also get updated via binding?

Directly s开发者_StackOverflow社区et the label's Content property won't work, it just simply clear the binding.


If you have to do it in code-behind, you can do something like that :

ViewModel vm = (ViewModel)this.DataContext;
vm.FileName = path;

(btw, your ViewModel class needs to implement INotifyPropertyChanged)

0

精彩评论

暂无评论...
验证码 换一张
取 消