Detect changes in Navigation property sets RRS feed

  • Question

  • Hello,

    I am developing a WPF application using .NET 4 and Entity Framework 4. I have generated the entity data model from the database using database first design.

    The application is build as follows, I have a customer object which contains navigation properties to other entities. This customer object is bound to fields in my WPF CustomerViewModel (I am using MVVM). When the entity is created or loaded from the database it is detached from the ObjectContext.

    I have validation enabled on the fields of my viewmodel and a progressbar will indicate to the user how far he is in entering the data.

    The problem is when the user selects data  from a combobox in the viewmodel for the navigation properties, there's no propertychanged event generated. So my progressbar does not display the current status till the user sets a primititve property, then a propertychanged event is generated and the progress bar is updated.

    Below is an example of one of these properties bound to a navigation set:

    <Label Grid.Column="0" VerticalAlignment="Center">Mailing:</Label>
    <ComboBox Grid.Column="1" Width="Auto"  
                ItemsSource="{Binding Mailings}"
                SelectedItem="{Binding CurrentEntityItem.SoortMailingSet, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, 
                            ValidatesOnExceptions=True, NotifyOnValidationError=True}"  
                Margin="10,5,100,6" HorizontalAlignment="Stretch"/>

    I have tried to attach PropertyChanged handlers to my navigation properties sets but this doesn't work when I create a new entity, because the sets are null when the entity is created.


            public void Init()
                this.MailingSet.PropertyChanged += new PropertyChangedEventHandler(PropertyChanged);
                this.CustomerGroupSet.PropertyChanged += new PropertyChangedEventHandler(PropertyChanged);
            void PropertyChanged(object sender, PropertyChangedEventArgs e)

    Can someone please tell me how you can track changes in navigation property sets of a particular entity.





    • Edited by marcel222 Monday, January 23, 2012 12:01 PM
    Monday, January 23, 2012 11:57 AM