Property grid editors (external)

Grids for WPF Forum

Posted 10 years ago by KC
Version: 4.5.0485
Avatar
I have 2 questions regarding property grid editors.

1) How can I have an ellipse type button displayed to launch an "external" editor? Like a separate Winform or WPF Window...

2) Is there any way to style the shared DateTimePicker control to only provide edit features for the TIME portion of the DateTime data type? I.e. I created a property editor type for DateTime, but, it popups the calendar that only allows edit of the date.

Thank you.

Comments (6)

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

1. We show how to do this in the Property Editors Quick Start in our Sample Browser. Look under the Color and String categories. There is an example for each.

2. The DateTimePicker doesn't support what you asking about. We are most of the way through development on a new product, called Editors for WPF, which includes a parts-based editor which can accomplish what you are asking (and much more ;-) More info can be found on our blog.

Hope this helps.


Actipro Software Support

Posted 10 years ago by KC
Avatar
Do you have an example of the use of the textbox and popupbutton from the text dialog sample created in code-behind (vb.net) and data binding? I need it to be a little more dynamic than creating and binding it within the xaml.

I.e. The appropriate popup editor is also determined by user interaction and the values of other properties at runtime. So, I need to create the data templates in code and bind within code.
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi KC,

We don't currently have an example, but it is on the TODO list. You can certainly build an editor from C#/VB.Net code. You would need to use a FrameworkElementFactory to build up the DataTemplate. Essentially, you create a FrameworkElementFactory for each element that exists in the DataTemplate, then construct a DataTemplate and assign your root FrameworkElementFactory to the DataTemplate.VisualTree property.

That gets you the DataTemplate. Assigning that to your property depends on how you are using the PropertyGrid. So I'm not 100% what the best route would be for you. Assuming you are using the SelectedObject(s) property, then you'd want to use the EditorAttribute. But again this can be assigned statically at compile-time (by decorating your properties with the attribute) or dynamically at run-time (by implementing ICustomTypeDescriptor). But in both cases you would need to implement a class that derives from PropertyEditor (in the ActiproSoftware.Windows.Controls.PropertyGrid.Editors namespace), which overrides the ValueTemplate property and returns the DataTemplate above (you can just leave the setter of ValueTemplate empty).

It sounds like you need to simply change the popup dialog depending on various factors. This could be accomplished using a fixed property editor (as seen in the Property Editors QuickStart). In the handler for the "show dialog" command, you would switch which dialog is shown as needed.


Actipro Software Support

Posted 10 years ago by KC
Avatar
Thanks. I already started doing as you mentioned in the first and last paragraph. I think that will allow me to do what I need. I was just hoping it would be a little less coding to do something like this.

If you know how to add a grid with 2 columns set columndefinitions etc. as a framework element and also how to grid.setcolumn on the child frameworkelements that would be helpful... or maybe i should use a stackpanel?

I like the flexibility of custom property editors... but it would be nice if the ability to display the popupbutton was already implemented within the PropertyGrid. I know there is more than one way that could be done...

But, I am happy with the PropertyGrid control so far... I was having many headaches with the WindowsFormsHost and Win PropertyGrid... so a WPF version was much needed.
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Depending on how flexible you need it, you can define your DataTemplates as resources and just load them via FrameworkElement.FindResource or you can use a ComponentResourceKey. This obviously makes it easier to define your DataTemplates, since you are working in XAML. Or you can look into using XamlReader.Load method.

You can define columns using some special handling in FrameworkElementFactory like so:
FrameworkElementFactory gridFactory = new FrameworkElementFactory(typeof(Grid));
FrameworkElementFactory columnDefinitionFactory = new FrameworkElementFactory(typeof(ColumnDefinition));
columnDefinitionFactory.SetValue(...);
gridFactory.AppendChild(columnDefinitionFactory);
As for setting the grid column on a child element (or any attached property such as DockPanel.DockProperty) you would just specify it as the dependency property like so:
myElementFactory.SetValue(Grid.ColumnProperty, 1);


Actipro Software Support

Posted 10 years ago by KC
Avatar
Thank you! I really appreciate the "extra" help beyond the PropertyGrid support ;-)
The latest build of this product (v2018.1 build 0675) was released 10 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.