Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: How to notify PropertyGrid that item in the Custom Editor has changed?

$
0
0
Hi,

I'm trying to create a PropertyGrid custom editor for the collections like ObservableCollection<T>.
Image
But the problem is that PropertyGrid control does not know about any changes in my editor.
How to tell the parent property grid that collection property has changed?

I added a INotifyPropertyChanged interface to my editor
    public partial class ListEditor : UserControl, ITypeEditor, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        PropertyItem _item;

        public ListEditor()
        {
            InitializeComponent();
        }

        public FrameworkElement ResolveEditor(PropertyItem propertyItem)
        {
            _item = propertyItem;
            if (_item.Value != null)
            {
                itemsList.ItemsSource = (ICollection)_item.Value;
                ((INotifyPropertyChanged)_item.Value).PropertyChanged += ListEditor_PropertyChanged;
            }
            return this;
        }

        void ListEditor_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            OnPropertyChanged("_item");
        }

        protected void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
        private void addItemBtn_Click(object sender, RoutedEventArgs e)
        {
            SingleItemEditor editor = new SingleItemEditor();
            Type t = itemsList.ItemsSource.GetType().GetGenericArguments()[0];
            Activator.CreateInstance(t);
            if (editor.ShowDialog(Activator.CreateInstance(t)) == true)
            {
                ((IList)itemsList.ItemsSource).Add(editor.item);
                itemsList.Items.Refresh();
            }
        }

        private void editItemBtn_Click(object sender, RoutedEventArgs e){}

        private void delItemBtn_Click(object sender, RoutedEventArgs e){}

        private void itemsList_SelectionChanged(object sender, SelectionChangedEventArgs e){}
    }
It doesn't works as expected.

I can track collection changes, but can't find a way to notify Property grid about them.

Thanks in advance for any help,
Xandro.

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>