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.

  • 相关阅读:
    进度条05
    计算机视觉基础(一)——左右手坐标系转换时R和T的具体形式分析
    使用unity3D开发同时打开手机前后摄像头实例程序
    使用OpenCV读取摄像头图像并显示
    Query on a tree II 倍增LCA
    Nuclear Power Plant ZOJ
    [AHOI2009]中国象棋 BZOJ1801 dp
    What Goes Up UVA
    Query on a tree 树链剖分 [模板]
    hdu 6196 搜索+剪枝
  • 原文地址:https://www.cnblogs.com/kongshu-612/p/5521544.html
Copyright © 2011-2022 走看看