INPC & RaizePropertyChanged in mvvmlight

INPC & RaizePropertyChanged in mvvmlight

In WPF app, MvvM Framework, we binding the UIElement from View to the Public Properties in ViewModel. what does the RaizePropertyChenged do while modifying the Public Properties.

RaizePropertiesChenged("") VS RaizeProertiesChanged("PropertiesName")

  1. According to MSDN,if we set the parameters as null or Empty, it indicate all properties on the object have changed. so, it means all the uielement binding to this object will reflesh. if we provide the propertyName, it will indicate only the target propetyName modificated, So, only uielement binding to this properties reflesh.

  2. when does the uielement reflesh? it will finish the refleshment when the RaizePropertyChanged finished. So, how does the sequences of the refleshing? which uielement will update? here, we base on the ParameterName, Firstly, the uielement directly binding to the Properties will reflesh.

  3. Be careful when we call RaizePropertyChanged() with empty or null paramter. Here is a sample

xaml:

<ComboBox ItemsSource="{Binding CustomerSpace.Customers, Source={StaticResource Locator}, Converter={StaticResource CustomersConverter}}" SelectedItem="{Binding SelectedCustomer ,Converter={StaticResource SelectedCustomerConverter}}"/>

<ComboBox ItemsSource="{Binding SelectedCustomer.Contacts , Converter={StaticResource ContactsConverter}}" SelectedItem="{Binding SelectedContact,Converter={StaticResource SelectedContactConverter}}"/>

cs:

 public Customer SelectedCustomer
        {
            get
            {
                return _SelectedCustomer;
            }
            set
            {
                _SelectedCustomer = value;
                RaisePropertyChanged("");
            }
        }
        
           public Contact SelectedContact
        {
            get
            {
                return _SelectedContact;
            }
            set
            {
                _SelectedContact = value;
                RaisePropertyChanged("");
            }
        }

In the SelectedContact, when we selected a contact from the contacts combobox, it will Set SelectedContact, then RaizePropertyChanged(""), it will notify all the uielement to reflesh uielement, the SelectedCustomer will update, => the Contacts of combobox will update, => then the SelectedContact will also update => it will call RaisePropertyChanged("") again, then here a loop here.


Summary about the uielement reflesh.

if the PropertyChanged event raized, all the uielement binding to this Property or to the subProperty of the Property, Be Noted about this, the reflesh process will recurse until all the uielement completing the reflesh.

转载于:https://www.cnblogs.com/kongshu-612/p/5521544.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值