This is a migrated thread and some comments may be shown as answers.

Parent property name with nested properties not updating

5 Answers 241 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Zberbang
Top achievements
Rank 2
Zberbang asked on 30 Dec 2013, 01:03 PM
Hello!

I encountered the problem with parent property name which not updates if I modify child properties.
I have a class which overrides ToString() to return format string of its properties. When I change one of that property I fire PropertyChanged but ToString() never calling again and I see old name of parent property on GUI.
But the name is changing and ToString() is calling on each expanding/collapsing or searching.

Is it by desing or I have to do smth extra?

Here is a sample project with Q2 2013 libs to illustrate the problem.

5 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 02 Jan 2014, 02:22 PM
Hi Zber,

In order to update the parent property when it's children are modified you have to do the following steps:
1. Implement INotifyPropertyChanged for the parent property
2. Add event handler to handle the PropertyChanged event.

I have modified your sample project with the necessary changes.

Regards,
Hristo
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Zberbang
Top achievements
Rank 2
answered on 09 Jan 2014, 02:05 PM
Hi Hristo,
thanks for explanation.
I have similar issue with collection editor - object name in left area is not refreshing on object changes.
I modified sample project to let Order have list of Employee. The only way to refresh Employee name in left area is to toggle parent object property Employees.

What should I do this time?

Here is a sample project.
0
Hristo
Telerik team
answered on 14 Jan 2014, 02:01 PM
Hi Zber,

Basically when you edit the item properties, you don't send notifications to the parent that it's children have changed. You would have to implement an ObservableCollection of INotifyPropertyChanged.

You can see a demonstration of this in our online demo located here. Additional information about Collection editor is located here.

Regards,
Hristo
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Zberbang
Top achievements
Rank 2
answered on 15 Jan 2014, 01:48 PM
Hi Christo,

Implementing an ObservableCollection of INotifyPropertyChanged won't cause correct updating object name on the left area.
You give me a link for silverlight demo and it's work as should but WPF demo don't.
I found the difference between two demos and found that silverlight version is changing template of CollectionEditorStyle:
<Style TargetType="telerik:CollectionEditor" BasedOn="{StaticResource CollectionEditorStyle}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding PropertyName}" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>

So that is the key to solve my problem.
0
Accepted
Hristo
Telerik team
answered on 17 Jan 2014, 03:29 PM
Hello Zber,

You will have to use the following style to update the UI when the first or last name is updated:
<Style TargetType="telerik:CollectionEditor">
     <Setter Property="ItemTemplate">
         <Setter.Value>
             <DataTemplate>
                 <TextBlock>
                     <TextBlock.Text>
                         <MultiBinding  StringFormat="{}{0}, {1} - {2}">
                             <Binding Path="LastName"/>
                             <Binding Path="FirstName"/>
                             <Binding Path="Department.Country"/>
                         </MultiBinding>
                     </TextBlock.Text>
                 </TextBlock>
             </DataTemplate>
         </Setter.Value>
     </Setter>
 </Style>

You can find more information about the string format property in the following article in msdn: article.

Regards,
Hristo
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
PropertyGrid
Asked by
Zberbang
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Zberbang
Top achievements
Rank 2
Share this question
or