enum only displayed as text

Grids for WPF Forum

Posted 14 years ago by Sascha Schwegelbauer
Avatar
Hi ActiPro,

I'm using an enum as value-source for a PropertyGridPropertyItem.
<app:PropertyGridPropertyItem DisplayName="InvoiceState"
ValueTemplate="{StaticResource {x:Static app:BuiltinEditors.ComboBoxValueTemplateKey}}"
Value="{Binding InvoiceState, Mode=TwoWay}" DefaultValue="False"
StandardValues="{Binding AllValues, Source={StaticResource ecInvoiceState}}"
IsLimitedToStandardValues="true" />
The ComboBox shows the enum-values correctly templated when dropped down, but the closed one just seems to display via a ToString() method.

How can I make PropertyGrid display the templated enum-value also in standard-condition?

Thanks in advance
Sascha

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Sascha,

Enum values should be automatically handled. So assuming the ecInvoiceState is an enum, and InvoiceState is a property of that type, then you should only need to set the Value property. If that is not what you are seeing, then please send a small sample project to our support address and we can take a look.

If you are doing something different or a little more customized, then you would need to build a custom property editor. The ComboBoxValueTemplateKey property editor uses a native WPF ComboBox with IsEditable always set to true (to more closely mimic the WinForms PropertyGrid). But this means that the selected item is displayed using a TextBox, instead of a ContentPresenter. The latter of which respects any DataTemplates you have defined.

Therefore, what you would need to do is build a custom property editor that doesn't set IsEditable to true. The only problem with this is that the ComboBox won't match the other entries in the property and would stand out (as it has a darker look in the Aero theme).

If you are a WPF Studio customer, you can download the default styles. This includes the ComboBoxValueTemplateKey definition, which you could simply tweak to your needs. If you are not a WPF Studio customer, you can send a request to our support address.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.