Skip to content

Conversation

ykarpeev
Copy link

If I have a viewmodel that I bind to the propertygrid that has a property such as:

   public List<string> ListOfStrings
   {
       get => this.AppSettings.Strings;

       set => this.AppSettings.Strings = value;
   }

When editing the collection I do not see the "set" called when the changes are made. This change allows for it to happen.

…itemssource - allows to see the change in view model
@XceedBoucherS
Copy link
Collaborator

Hello,

I wrote a sample to test your situation. Please correct it if not accurate.

<StackPanel> <xctk:PropertyGrid SelectedObject="{Binding}" /> <Button Content="TEST" Click="Button_Click" /> </StackPanel>

`public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

this.DataContext = new MyObject();
var testObjectCount = (this.DataContext as MyObject).ListOfStrings.Count;  // returns 0 item.

}

private void Button_Click( object sender, RoutedEventArgs e )
{
var testObject = this.DataContext as MyObject;
var testObjectCount = testObject.ListOfStrings.Count; // returns the X items added.
}
}

public class MyObject
{
List m_list = new List();

public string Name { get; set; }

public List ListOfStrings
{
get => m_list;

set => m_list = value;

}
}`

Steps:
-Run the app
-A breakpoint on line
var testObjectCount = (this.DataContext as MyObject).ListOfStrings.Count; // returns 0 item.
will return no items in the list.
-Use the PropertyGrid to add 3 items in the list.
-Click the Button
-A breakpoint on line:
var testObjectCount = testObject.ListOfStrings.Count; // returns the X items added.
will return a list with 3 items.

so the MyObjects is correctly updated.
Am I missing something ?
Thanks

@ykarpeev
Copy link
Author

ykarpeev commented Sep 8, 2025

For me I was using MVVM and here is what I have:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>

        <xctk:PropertyGrid SelectedObject="{Binding}"></xctk:PropertyGrid>
    </Grid>
</Window>
 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new MainViewModel();
        }
    }

    public class MainViewModel
    {
        public List<string> test = new List<string>();

        public List<string> Test
        {
            get
            {
                return test;
            }

            set
            {
                test = value;
            }
        }
    }

When changing the collection in the propertygrid the Set method on Test is never called - but it does work with these changes.

@XceedBoucherS
Copy link
Collaborator

The setter of MainViewModel.Test won't be called because this collection is always the same. Only its content is modified through the PropertyGrid Collection Editor.

@ykarpeev
Copy link
Author

ykarpeev commented Sep 9, 2025

Thanks. In this case for me the propertygrid is bound to a configuration class & when the Set is called on a property I save the settings to a file & so having an indification that the collection changed works really well. That's why I made this change - I couldn't find a way to get that notification any other way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants