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
|
Hi, I am facing a problem while I am trying to create datatemplate for enum types. Attached is s sample that demonstrates the same. It has four Labels and the PropertyGrid displays the properties of the Label which is clicked. I have created a template for the 'HorizontalContentAlignment'. Have used SelectedObjects for binding to the PG instead of SelectedObject because in the real scenario for my application, I need just that. Problem is when I change the HorizontalContentAlignment for 'Label1' to Right and then click on Label2 the property of Label2 also changes to Right. Please see the attach sample, and let me know what I am doing wrong. If I dont use template, everything works fine as expected. Thanks |
|
|
You need to remove the IsSynchronizedWithCurrentItem attribute. This is basically causing WPF to store "Right" as the current selected value of the enum names collection, and I think that's causing it to apply that selection back through the binding when it changes. However, if you try this you will run into a couple of other issues. The first is that the text of the combo box will appear blank. This is because your GetEnum ObjectDataProvider is returning strings but the SelectedItem of the ComboBox is a HorizontalAlignment. You can fix this by changing the ObjectDataProvider's MethodName from GetNames to GetValues. The second is that you may get binding errors when selecting a value: the debug window reports cast errors and the value is not saved to the object. (I think your current code will not run into this problem but I'm mentioning it just in case.) This will occur if you do not set PropertyEditor.DeclaringType in a multi-select scenario: the custom editor matches the name so it overrides the default ManyEditor, so the custom editor tries to edit the Many object directly. But a HorizontalAlignment is not a Many so this fails. The solution for this is to specify the declaring type. Note that this should be the declaring type, i.e. the type of the object which defines the property, NOT the data type of the property itself. In fact, it's a bug that the custom editor is being shown at all in your case, because the HorizontalContentAlignment property is declared on Control, NOT on HorizontalAlignment. So in the end what you want is for your editor declaration to look like this: <ms:PropertyEditor PropertyName="HorizontalContentAlignment" and your ObjectDataProvider to look like this: <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type Sys:Enum}" x:Key="GetEnum"> With those changes in place it works for me -- please let me know if you still see problems! |
|
|
Sorry for replying so late My problem was fixed with the suggestions you gave. Thank you |
|