Show/Hide properties

Grids for WPF Forum

Posted 9 years ago by Eli Obadia
Avatar
I'm working with SelectedObject and need to show/hide some properties according to the value of another property. For example if a property is marital state, when the value is married I need to show another property that has wife name, and when the marital status change to single I need to hide the property wife name.

I'm trying to use the following code for the samples From the Custom Filters:


       public class CustomFilter : DataFilter {

              /////////////////////////////////////////////////////////////////////////////////////////////////////
              // PUBLIC PROCEDURES
              /////////////////////////////////////////////////////////////////////////////////////////////////////

              /// <summary>
              /// Determines if the specified <see cref="IDataAccessor"/> should be filtered.
              /// </summary>
              /// <param name="dataAccessor">The data accessor.</param>
              /// <returns>
              /// <c>true</c> if the specified <see cref="IDataAccessor"/> should be filtered; otherwise <c>false</c>.
              /// </returns>
              public override bool Filter(IDataAccessor dataAccessor) {
                     if (this.IsEnabled) {
                           ICategoryDataAccessor categoryDataAccessor = dataAccessor as ICategoryDataAccessor;
                           if (null != categoryDataAccessor && "Misc" == categoryDataAccessor.DisplayName)
                                  return true;
                     }
                     return false;
              }

       }
And add in the .xmal:

                           <propgrid:PropertyGrid.DataFilter>
                                  <sample:CustomFilter x:Name="customFilter" />
                           </propgrid:PropertyGrid.DataFilter>

But I have 2 questions:

1) In this sample the filtering code is activated by “binding” but I will need to make a “call” to do the filtering from my code -so when the user change the value of the property Marital_Status I cann show/hide the wife_name property- how can I do that ?

2) Here the sample is filtering an entire category, how can I filter one specific property inside a category?

Comments (6)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Eli,

We answered your question via the ticket you created, but we are including the answer here for others to find.

1. You can call PropertyGrid.Refresh to re-apply the DataFilter.

2. The filter is passed any IDataAccessor that will be presented by the PropertyGrid. So you can cast the IDataAccessor to ICategoryDataAccessor, ICategoryEditorDataAccessor, or IPropertyDataAccessor. So in your case,
you'd want to cast it to IPropertyDataAccessor and check if it's ValueName
is equal to a given property name.

The filter is only applied when the control is being populated. So if the properties you want to filter changes (based on whatever logic) you would need to "refresh" the PropertyGrid by called Refresh() (per #1 aboev). This has the disadvantage of refreshing the entire control, which moves the focus and resets the expansion state of the nodes.


Actipro Software Support

Posted 8 years ago by Fatema
Avatar
Hi,

we want to have the same effect without property refresh.
Is there any other way either by binding a value or so as this refresh of property grid flashes the UI which is a bit irritating.

Regards,
Fatema
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Unfortunately, not at this time, but we'll mark down a TODO item to see about enhancing this feature.

We are currently leveraging the WPF ListCollectionView and it's Filter property. The only way to reapply this filter is to call it's Refresh method, which tells the associated ItemsControl (i.e. PropertyGrid) to recreate it's items.


Actipro Software Support

Posted 8 years ago by Eli Obadia
Avatar
Any progress on this ToDo item?

Thanks,
Eli
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Eli,

No, there hasn't been any progress on that TODO item. We just posted the TODO item yesterday. There are several higher priority items that we need to complete before considering this item.

We would effectively have to rewrite WPF's ListCollectionView and make it smarter and I'm not entirely sure that is possible (due to several classes/members marked as private or internal in WPF).


Actipro Software Support

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Just FYI, we've added a sample for the next maintenance release that shows how a custom data factory and property data accessor can be used to show/hide properties based on the value of another property. This also works without having to refresh the PropertyGrid.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 9 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.