Hi,
We are evaluating the xamPropertyGrid, and we are testing a special case that doesn´t appears inside the Infragistics Samples 16.1.
In our test case, we are using a ViewModel inheriting from CustomTypeDescriptor. In this View Model we have a List, and in the GetProperties method we are getting the properties of the list objects. This objects are coming with a PropertyDescriptor to modify the DisplayName, the Category depending of the object properties.
We want to show only the list objects, we don´t want to show the collection item concentrator.
In our example, we have two controls:
The problem is that the property grid doesn´t refresh the data, if we update the data from button´s event.
I attached a solution with the problem.
What are we doing wrong? Which is the correct way?
Hello David,
Thank you for providing a sample!
I have taken a look at the sample and the reason why the XamPropertyGrid does not refresh its data is that ListGenericViewModel view model class is not raising change notifications for the ParameterViewModel view model class. In other words, XamPropertyGrid is listening for property change notifications on ListGenericViewModel and in this case we need to raise change notifications for the ParameterViewModel.
What you could do is to hook to the PropertyChanged event handler when adding the ParameterViewModels.
That is a snippet code illustrating the notification for the ParameterViewModel:
public ListGenericViewModel(string prefix) { ParameterViewModel pvm = new ParameterViewModel(prefix) { Value = prefix, Name = "First Name", Category = "Personal Data" }; Properties.Add(pvm); pvm.PropertyChanged += Pvm_PropertyChanged;
pvm = new ParameterViewModel("Garc�) { Value = "Garc�, Name = "Last Name", Category = "Personal Data" }; Properties.Add(pvm); pvm.PropertyChanged += Pvm_PropertyChanged; }
private void Pvm_PropertyChanged(object sender, PropertyChangedEventArgs e) { ParameterViewModel pvm = sender as ParameterViewModel;
OnPropertyChanged(pvm.Name); }
Please take a look at the modified version of the sample and let me know if you have any questions on this matter.
Hello Martin,
Thank you for you answer. It works fine, but the square that indicates that the value is not the default don´t change and I cannot reset the value thrown the context menu.
Thank you in advance.
Thank you for your answer, all works fine. Additionally, I checked the merge capability and it works fine also.
In order to make the "Reset Value" menu option enabled, couple of things should be made
Step 1, change the constructor of ParameterPropertyDescriptor to include an array of attributes and pass them to the base PropertyDescriptor constructor like so:
/// <summary> /// Initializes a new instance of the <see cref="ParameterPropertyDescriptor"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="attrs">The attrs.</param> /// <param name="model">The model.</param>// public ParameterPropertyDescriptor(ParameterViewModel model, object component) : base(model.Name, new Attribute[] { })
public ParameterPropertyDescriptor(ParameterViewModel model, object component, Attribute [] attributes) : base(model.Name, attributes)
Step 2, add a DefaultValue property to ParameterViewModel so we can access the property’s default value from the code in step 3 below:
internal string DefaultValue { get { return _valueDefaultMethod; } }
Step 3, modify the ListGenericViewModel.GetProperties() method to pass along a DefaultValueAttribute (making use of the DefaultValue property defined in step 2) for each property when constructing its ParameterPropertyDescriptor like so:
private PropertyDescriptorCollection _propertyDescriptorCollection;
public override PropertyDescriptorCollection GetProperties() { if (null == this._propertyDescriptorCollection) { this._propertyDescriptorCollection= new PropertyDescriptorCollection(null); foreach (var property in Properties) { //this._pdc.Add(new ParameterPropertyDescriptor(property, this)); this._pdc.Add(new ParameterPropertyDescriptor(property, this, new Attribute[] { new DefaultValueAttribute(property.DefaultValue) })); } }
return this._pdc; }
Step 4, Set the model.Value in ParameterPropertyDescriptor's SetValue override method
public override void SetValue(object component, object value) { model.Value = value.ToString(); }
Please take a look at the modified version of the sample and let me know if you have any concerns.