• 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.

  • 相关阅读:
    php过滤表单提交的html等危险代码
    浅析php过滤html字符串,防止SQL注入的方法
    PHP简单判断手机设备的方法
    如何用Math.max.apply()获取数组最大/小值
    Ubuntu14.04升级到Ubuntu16.04
    4、python数据类型之列表(list)
    3、python数据类型之字符串(str)
    centos7网卡名称修改以及配置
    rsync简单总结
    8、kvm虚拟机添加硬盘
  • 原文地址:https://www.cnblogs.com/kongshu-612/p/5521544.html
Copyright © 2020-2023  润新知