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

Changes to object properties not updating RadPropertyGrid

1 Answer 560 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Dano
Top achievements
Rank 1
Dano asked on 19 Apr 2018, 10:26 PM

Hello,

I'm binding to multiple items using PropertySetMode="Intersection" and CurrentPropertySet.  Changes to the properties from the PropertyGrid combobox work as expected, but changes to the objects from anywhere else in the application do not cause the PropertyGrid to update until the item selection is refreshed.  The objects implement INotifyPropertyChanged.  Is there something else I'm missing to get the changes to be shown in the PropertyGrid?

Here is some of the relevant XAML and my view model:

<DataTemplate x:Key="TemplateComboBoxTemplate">
    <telerik:RadComboBox ItemsSource="{Binding Clubs, Source={StaticResource MyViewModel}}"
                         SelectedValue="{Binding CurrentPropertySet[ClubID], Mode=TwoWay}"
                         SelectedValuePath="ID"
                         DisplayMemberPath="Name"
                         Margin="0">
    </telerik:RadComboBox>
</DataTemplate>
 
<telerik:RadPropertyGrid
    Item="{Binding Players}" 
    PropertySetMode="Intersection"
AutoGeneratePropertyDefinitions="True"
    AutoGeneratingPropertyDefinition="RadPropertyGrid_AutoGeneratingPropertyDefinition"/>

 

public class MyViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
 
    private ObservableCollection<Club> clubs;
    private ObservableCollection<Player> players;
    private List<Player> playersTemp = new List<Player>();
 
    public MyViewModel()
    {
        clubs = new ObservableCollection<Club>();
        Club club;
 
        // Liverpool
        club = new Club("Liverpool", new DateTime(1892, 1, 1), 45362, 1);
        club.Players.Add(new Player("Pepe Reina", 25, Position.GK, "Spain", 1, true));
        clubs.Add(club);
 
        // Manchester Utd.
        club = new Club("Manchester Utd.", new DateTime(1878, 1, 1), 76212, 2);
        club.Players.Add(new Player("Edwin van der Sar", 1, Position.GK, "Netherlands", 2, false));
        clubs.Add(club);
 
        // Chelsea
        club = new Club("Chelsea", new DateTime(1905, 1, 1), 42055, 3);
        club.Players.Add(new Player("Petr Čech", 1, Position.GK, "Czech Republic", 3, true));
        clubs.Add(club);
 
        // Arsenal
        club = new Club("Arsenal", new DateTime(1886, 1, 1), 60355, 4);
        club.Players.Add(new Player("Manuel Almunia", 1, Position.GK, "Spain", 4, false));
        clubs.Add(club);
 
        players = new ObservableCollection<Player>(clubs.SelectMany(c => c.Players));
    }
 
    public ObservableCollection<Club> Clubs
    {
        get
        {
            return this.clubs;
        }
    }
 
    public ObservableCollection<Player> Players
    {
        get
        {
            return this.players;
        }
    }
 
    internal void ClearPlayers()
    {
        playersTemp.AddRange(players);
        players.Clear();
        OnPropertyChanged(nameof(Players));
    }
 
    internal void SelectPlayers()
    {
        foreach (var player in playersTemp)
        {
            players.Add(player);
        }
        playersTemp.Clear();
        OnPropertyChanged(nameof(Players));
    }
 
    protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
    {
        PropertyChangedEventHandler handler = this.PropertyChanged;
        if (handler != null)
        {
            handler(this, args);
        }
    }
 
    private void OnPropertyChanged(string propertyName)
    {
        this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
    }
}

I prepared a sample project starting from another sample I found on this forum but I was unable to upload. I can provide this if it helps.

Thanks for any help you can offer!

1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 24 Apr 2018, 02:10 PM
Hello Dan,

Thank you for the provided xaml.

I tried to reproduce the described behavior on my side, but I am afraid I was not able to. This is why I am attaching the sample project that I used. May I ask you to share what you are doing differently on your side? What I can suggest is opening a new support ticket and attaching the project there. Additionally, if you can provide steps, which I can follow in order to reproduce the described behavior, I will be able to better assist you.

On a side note, you can check out the Property Sets article in our documentation, if you have not done so already.

I am looking forward to your reply.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
PropertyGrid
Asked by
Dano
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or