how to display a Interop-based type editor inside the WPF propertygrid.

Grids for WPF Forum

Posted 10 years ago by Michel Theunissen
Version: 14.2.0611
Avatar

Hi,

Is there an example with basic code for how to use 'WinFormsInteropValueTemplateSelector'. I am stuck and can't make it work.

I am trying to limit a property to a list of choices, but unfortunately this list depends on the value of another property. So, if the other property changes, I need to re-load the list. Therefore, a TypeEditor wouldn't work since it doesn't refresh, only when the object is assigned to the PropertyGrid.

I tried using a WPF Custom Type Editor, but am not sure on how I can bind my list of values into the data template. Therefore I was hoping to use the old-style UITypeEditor.

 

Thanks,

 

Michel

Comments (4)

Posted 10 years ago by Michel Theunissen
Avatar

Sorry, I meant to say: A TypeConverter wouldn't work for this case and I need a TypeEditor instead.

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michel,

I wouldn't recommend using the WinForms interop unless you absolutely have to.  Unfortunately we don't have any samples for it.

It sounds like you would be best suited to dynamically build a list of StandardValues for the property data accessor.  If you set a TypeConverter to the property data accessor, and if that TypeConverter supports standard values, then those standard values should get used in the property editor.

Perhaps what you could do is inherit one of our data factories (see the Custom Factory QuickStart for example) and return all the default IPropertyDataAccessor values from GetProperties override.  However if the data accessor for that one property is getting returned, then set the appropriate TypeConverter on it.  You could watch for the other property value to change (could even watch PropertyGrid events like in the Property Events QuickStart) and then call Refresh() on the data accessor or the entire PropertyGrid to requery the data factory.


Actipro Software Support

Posted 10 years ago by Michel Theunissen
Avatar

Hi,

Thanks so much for responding. I really appreciate it.

I found that WinForms editors have some issues , because it overwrites the standard collection editors. It wouldn't work unless I put the WinForms interop converter in Highest priority mode, which in turn would overwrite everything else.

I tried using a TypeConverter, but they are limited because they are only created once, and GetStandardValues() is only called once when the object is assigned to the grid.

For the concerning property I would like a dropdown to show up of a list of items whose contents is dynamic and depends on the value of another property which is represented by a dropdown and allows me to change its value.

I actually have something going now but WPF isn't my strongest. I looked at the custom editor example and from there I started doing something similar.  The main issue I'm facing is that some of the things are defined as static and won't allow me to easily get to my objects directly through the XAML code.

Ideally, the thing I'm looking for is to have a dropdown use the MVVM mechanism and show a viewmodel for a specific view. Right now, the XAML represents the ViewModel (or data template), but I'm having a hard time binding controls in the data template back to my view model without using static definitions.

Regaridng the data accessor, that may be the best way to do it. I'll have to play around with it.

 

Thanks so much,

 

Michel

 

Ideally,

Posted 10 years ago by Michel Theunissen
Avatar

Hi,

I was able to accomplish what I wanted somehow. I wanted to associate my own View/ViewModel (using MVVM) to the PopupContent. I was able to do this by placing a ContenPresenter inside the PopUpContent:

<shared:PopupButton.PopupContent>

    <ContentControl Content="{Binding RelativeSource={RelativeSource AncestorType={x:Type propgrid:IPropertyDataAccessor}}, Mode=OneWay, Converter={StaticResource MotionEditorViewConverter}}"/>

</shared:PopupButton.PopupContent>

Then, I also add a Converter for this ContentControl which generates the ViewModel that takes the IPropertyDataAccessor as a parameter to its constructor and I can basically set/get the property now from within my own view model. I addition, I also have access to the Property.Target, the parent class of the properties. The Target is explicitly implemented in the DataGridAccessorItem and therefore couldn't access it directly within the PopupContent. From the viewmodel I can cast and have access to this so I can see all other properties in my class that I like this viewmodel to depend on).

The PopUpContent itself is placed inside a DataTemplate (I saw another thread in the discussion forums regarding this) and is returned by a PropertyEditor and overwriting the "ValueTemplateKey"

Thanks so much for all you support.

Michel

The latest build of this product (v24.1.3) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.