Bonjour tout le monde,
Est-il possible de connaître l'objet qui est modifié dans la callback PropertyValueChanged d'une PropertyGrid ? Je m'explique : dans le but d'implémenter un Ctrl-Z dans mon application, je souscrit à l'évenement PropertyValueChanged pour stocker les paramètres qui ont changés :
et dans ma classe PropertyCommand :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public class MyPropertyGrid : PropertyGrid { public MyPropertyGrid() { InitializeComponent(); this.PropertyValueChanged += PropertyChanged; } private void PropertyChanged( object sender, PropertyValueChangedEventArgs args ) { commandManager.Do( new PropertyCommand( this.SelectedObject, args.ChangedItem.PropertyDescriptor, args.ChangedItem.Value, args.OldValue ); } }
Le problème, c'est que le champ this.SelectedObiect ne correspond pas toujours à l'objet qui vient d'être modifé : ce n'est pas le cas par exemple si l'on a des objets imbriqués dans la propertygrid, et du coup, les méthodes Do() et Undo() provoquent des exception...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class PropertyCommand : ICommand { public PropertyCommand( object self, PropertyDescriptor property, object newValue, object oldValue ) { self_ = self; property_ = property; newValue_ = newValue; oldValue_ = oldValue; } public void Do() { property.SetValue( self_, newValue_ ); } public void Undo() { property_.SetValue( self_, oldValue_ ); } private readonly object self_; private readonly PropertyDescriptor property_; private readonly object newValue_; private readonly object oldValue_; }
J'ai beau chercher dans la classe PropertyGrid ou dans GridItem (et dans la doc MSDN), je ne trouve pas ce fameux objet modifié. Toutte aide serait la bienvenue, merci d'avance.
Partager