zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    Goolge-Guava Concurrent中的Service
    Golang操作数据库
    HttpContext
    office 问题集
    C# 日志使用
    字符编解码的故事 字符集 GBK GB2312 GB18030 Unicode 的由来和区别
    TCP UDP 协议的选择
    WebService 学习总结
    WebService 学习过程
    Archery:开源漏洞评估和管理工具
  • 原文地址:https://www.cnblogs.com/kongshu-612/p/5521544.html
Copyright © 2011-2022 走看看