[C#]当从其他userControl更新vm时,如何刷新xaml绑定数据 [英] [C#]How to refresh xaml binding data when it's vm is updated from other userControl

查看:72
本文介绍了[C#]当从其他userControl更新vm时,如何刷新xaml绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件 在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

推荐答案

确保您的"数据" class实现了INotifyPropertyChanged接口,并在"item"的setter中引发了PropertyChanged事件。您尝试设置的属性:

Make sure that your "data" class implements the INotifyPropertyChanged interface and raise the PropertyChanged event in the setter of the "item" property that you are trying to set from:

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绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆