This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, I have more than one window, each window has a PropertyGrid and an object behind. The objects have some same Properties, and I define my own data templates for some Properties. Below are some example xaml code of two windows:
< ms:PropertyGrid Grid.Row="1" Name="propertyGrid1" Grouping="{x:Static ms:PropertyGrouping.ByCategory}" IsToolBarVisible="True" Margin ="20">
<ms:PropertyGrid.Editors >
<ms:PropertyEditor PropertyName="Internal" EditorTemplate="{StaticResource {x:Static ms:PropertyGrid .CheckBoxEditorKey}}" />
<ms:PropertyEditor PropertyName="Source" EditorTemplate="{StaticResource EllipsesEditor}" AllowExpand ="True" />
<ms:PropertyEditor PropertyName="OutputSettings" EditorTemplate="{StaticResource EllipsesEditor}" AllowExpand ="True" />
<ms:PropertyEditor PropertyName="ResultsFolder" EditorTemplate="{StaticResource ResultsFolderEditor }" />
<ms:PropertyEditor PropertyName="BuildSettings" EditorTemplate="{StaticResource EllipsesEditor}" AllowExpand ="True" />
<ms:PropertyEditor PropertyName="IndexCols" EditorTemplate="{StaticResource IndexColsEditor}" />
</ms:PropertyGrid.Editors >
</ ms:PropertyGrid >
< ms:PropertyGrid Grid.Row="1" Name="propertyGrid2" Grouping="{x:Static ms:PropertyGrouping.ByCategory}" IsToolBarVisible="True" Margin ="20">
<ms:PropertyGrid.Editors >
<ms:PropertyEditor PropertyName="Internal" EditorTemplate="{StaticResource {x:Static ms:PropertyGrid .CheckBoxEditorKey}}" />
<ms:PropertyEditor PropertyName="Source" EditorTemplate="{StaticResource EllipsesEditor}" AllowExpand ="True" />
<ms:PropertyEditor PropertyName="OutputSettings" EditorTemplate="{StaticResource EllipsesEditor}" AllowExpand ="True" />
<ms:PropertyEditor PropertyName="ResultsFolder" EditorTemplate="{StaticResource ResultsFolderEditor }" />
<ms:PropertyEditor PropertyName="BuildSettings" EditorTemplate="{StaticResource EllipsesEditor}" AllowExpand ="True" />
<ms:PropertyEditor PropertyName="IndexCols" EditorTemplate="{StaticResource IndexColsEditor }" />
<ms:PropertyEditor PropertyName="Targets" EditorTemplate="{StaticResource EllipsesEditor }" />
<ms:PropertyEditor PropertyName="RunCode" EditorTemplate="{StaticResource EllipsesEditor}" />
</ms:PropertyGrid.Editors >
</ ms:PropertyGrid > As you can see, I copied the below block of code from one window to the other.
<ms:PropertyEditor PropertyName="Internal" EditorTemplate="{StaticResource {x:Static ms:PropertyGrid.CheckBoxEditorKey}}" />
<ms:PropertyEditor PropertyName="Source" EditorTemplate="{StaticResource EllipsesEditor}" AllowExpand ="True" />
<ms:PropertyEditor PropertyName="OutputSettings" EditorTemplate="{StaticResource EllipsesEditor}" AllowExpand ="True" />
<ms:PropertyEditor PropertyName="ResultsFolder" EditorTemplate="{StaticResource ResultsFolderEditor }" />
<ms:PropertyEditor PropertyName="BuildSettings" EditorTemplate="{StaticResource EllipsesEditor}" AllowExpand ="True" />
<ms:PropertyEditor PropertyName="IndexCols" EditorTemplate="{StaticResource IndexColsEditor}" />
Is there any way I can avoid copying this block of code? For example, could I put this block of code in a third window, and include that window in the above two windows? Thanks in advance. |
|
|
Unfortunately I don't think this is possible. The Editors collection is not a dependency property and is therefore not styleable (and the WPF styling system doesn't support adding to collections anyway). You might be able to do it by declaring each PropertyEditor as a resource in a shared dictionary, and include them by using StaticResourceExtension elements, but you would still need to reproduce the list of resource references in each grid instance. |
|
|
Is it possible to overwrite some Editor Templates? For example, the PropertyGrid shows a combobox for each bool type property by default. But, my boss wants it to be a checkbox and he doesn't want to use
EditorTemplate ="{StaticResource {x:Static ms:PropertyGrid.CheckBoxEditorKey}}" for each bool type property in the PropertyGrid.Editors. |
|
|
Use a TypeEditor with the EditedType set to "{x:Type sys:Boolean}" (where the sys: xmlns is mapped to System/mscorlib). Note that the property grid always uses the *first* matching editor, so if you want to specify custom PropertyEditors for some boolean properties, they have to appear *before* the TypeEditor. So you'll probably want to put this TypeEditor near the bottom of the editor declarations list. |
|