问题描述
我有一个用户控件 在MainPage中,UserControl中的UserControlViewModel包含数据,MainPage中的MainPageViewModel包括ObservationCollection< data>,当我在UserControl中的数据发生变化时,我使用了 ((Window.Current.Content
as Frame).content as MainPage).MainPageViewModel.datas.single()。item = value但是,MainPage中的XAML数据没有刷新。任何人帮助
I have a usercontrol in MainPage,a UserControlViewModel in UserControl include data,a MainPageViewModel in MainPage include ObservationCollection<data>, When my data in UserControl changed,and I use ((Window.Current.Content as Frame).content as MainPage).MainPageViewModel.datas.single().item= value to update however,the XAML data in MainPage didn't refresh . Anyone help
推荐答案
public class data : INotifyPropertyChanged
{
private object _value
public object item
{
get { return _value; }
set { _value = value; NotifyPropertyChanged(); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
请提供所有相关代码和标记摘要你需要任何进一步的帮助。
Please provide all relevant code and markup snippets if you need any further help.
希望有所帮助。
Hope that helps.
请记得通过标记有用的帖子来关闭你的主题作为答案,如果你有一个新问题,然后开始一个新的线程。请不要在同一个帖子中提出几个问题。
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
这篇关于[C#]当从其他userControl更新vm时,如何刷新xaml绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!