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'm trying to make a custom editor template in the 'Alloy' style: <ms:PropertyEditor PropertyName="Foo"> The problem is the editor is behaving as if it's read only: the drop down appears, but I cannot change the selected item. If I don't specify the style, there is no problem. So I decided to look at the source for the styles ComboEditor and ReadOnlyComboEditor, and noticed that they are identical, save their names. Is this an error, or am I just going about things the wrong way? Thank you. |
|
|
First, I think the ReadOnlyComboEditor name is a bit misleading -- I believe it actually handles the case where the user is not allowed to type text into the combo box, but the user can still select things from the drop-down. If it's the same as the "can type text" editor then this may be a bug. That aside, I think you're going about things the right way (though note that to hook this up to the edited object you will need to bind SelectedItem), but there may be an issue with the custom style. (You observe that if you don't specify the style there is no problem which reinforces this theory.) If you copy the Alloy ComboEditor style resource exactly, do you still get the problem? Could you post your ComboEditor style resource please? Thanks! |
|
|
Thanks again for the quick response. I should mention that I didn't write this style, it's from Mindscape's Alloy.xaml: <Style x:Key="ComboEditor" TargetType="{x:Type ComboBox}"> |
|
|
Hmm, it seems the Alloy template is making a couple of assumptions. To make the template work as written, you need to do two things (which you will want to be doing anyway, which is why it normally works): 1. You are not currently binding the ComboBox.SelectedItem. In your DataTemplate, you need to add the following: SelectedItem="{Binding Value, Mode=TwoWay}" 2. Ensure that the selected object fires PropertyChanged notifications for the Foo property. However, as a more general solution, the Text property of the TextBlock in the template should probably have been defined as follows: Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" (instead of Text="{Binding Path=Value}") This will enable you to reuse the style more generally. You will still need to make the other changes for the property grid to successfully bind to the Foo property though. Please let me know if you need more info or still see problems or if you want me to post my code. |
|
|
I'm also seeing some niggles with all three of the example styles. In the Alloy style, I cannot actually see any code difference *at*all* between the ReadOnlyComboEditor and the ComboEditor styles. I have a niggling suspicion that the copy-paste bandit has struck again and we really need a <TextBox> rather than a <TextBlock> in the ComboEditor version. To quickly test this, try adding the following to the GridStyles MainWindow: <ms:PropertyEditor PropertyName="Item[0]" EditorTemplate="{StaticResource {x:Static ms:PropertyGrid.ListSelectEditorKey}}"/> Then look at the very simple case of the Accessories list. Compare the Alloy, Whalesong and Radium styles with the null style. I wouldn't expect any of them to work correctly (since Accessories is just a list of Strings, the combobox has no items in it's list), but you'll see that you can't even get keyboard focus in the field with the non-null styles, and you do with the null style. |
|
|
Thanks for letting us know about this. The styles will be corrected in nightly builds dated 4 July 2009 and above, available from about 1430 GMT. Please let us know if you notice any other quirks or errors! |
|