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

  • 相关阅读:
    【软件构造】写在前面的话和课程介绍(完结)
    【论文阅读】分布一致性算法Paxos 《The Part-Time Parliament》
    2020秋遇到的有用的连接
    我的编程,菜菜菜
    隐马尔科夫模型 HMM(Hidden Markov Model)
    【论文阅读】An Empirical Study of Architectural Decay in Open-Source Software
    【论文阅读】An Anchor-Free Region Proposal Network for Faster R-CNN based Text Detection Approaches
    【论文阅读】DGCNN:Dynamic Graph CNN for Learning on Point Clouds
    【DeepLearning】GoogLeNet
    【DeepLearning】AlexNet
  • 原文地址:https://www.cnblogs.com/kongshu-612/p/5521544.html
Copyright © 2020-2023  润新知