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 attempting to use a property editor to provide a combo box as the editor. Unfortunately, when the property grid loads, the current value for the property does not appear as the 'SelectedValue' in the combo box ... the combo box appears blank, although the correct drop down options do display once one clicks the 'down arrow' on the combo box ... How do I get my SelectedValue to appear in the combo box? I'm new to the wonders of WPF ... but, I think I'm putting the right stuff in here .... Here is my DataTemplate: < DataTemplate x:Key='StyleEditor'> <ComboBox SelectedItem="{Binding Value}"> <ComboBoxItem>IntPageHdr</ComboBoxItem> ... Other items here ... <ComboBoxItem>IntNoteLabel2</ComboBoxItem> </ComboBox> </DataTemplate>Here is my PropertyGrid ... with the PropertyEditor ... < ms:PropertyGrid Name="uxPropertiesGrid"> <ms:PropertyGrid.Editors> <ms:PropertyEditor PropertyName='Style' DeclaringType='{x:Type uxpd:PhraseViewModel}' EditorTemplate='{StaticResource StyleEditor}'/> </ms:PropertyGrid.Editors> </ms:PropertyGrid>The object i'm binding to (PhraseViewModel) has a public property of 'Style'. The value for style doesn't show up in the combo box as the SelectedValue ... What am I doing wrong? Also, would you recommend an alternative approach to providing drop down values for a combo box? Regards, Douglas |
|
|
Ok, I finally got this simple thing to work .... I threw away my embedded (hard-coded) list of Style values ... and hooked up an XML data source ... and that didn't work ... Then I created a simple class to act as an objectDataSource to serve up a List(Of String) objects ... and viola! It worked .. I now get the current value of my selected object's 'Style' property displayed in the combo box ... This is my first foray in to the WPF world ... and to be honest ... this Microsoft framework still feels a bit 'shaky' ... my WPF project(s) routinely crash my Visual Studio 2008 SP1 instance and then wierd things like this .... but, I will press on ... ;-) ... Regards, Douglas |
|
|
Hello Douglas, Glad you got that sorted. For future reference you might want to look at http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=1341. Note in particular the issue with XML data (though that said, it appeared to work on 3.5 SP1, which is what you have, so this may be something different -- XPath bindings can be very confusing because they tend to render what looks like the right string but to actually *be* an XmlElement and therefore not compatible with a string property). (I suspect the reason your first version didn't work was similar -- the SelectedItem of the ComboBox was a ComboBoxItem, not a string, so didn't equal the string property value.) As you have identified, using an ItemsSource of strings is the way to tackle this because now your SelectedItem is a string, like the property you want it to bind to. Yes, the Visual Studio tooling for WPF is still disappointingly shaky. It is usually a bit better if you forget about the visual designer and just use it as a XAML editor, though still prone to slowdowns and the occasional crash. The framework itself is pretty good though, I think. It does feel weird at first, and definitely requires a change of mindset, but once you click into the way WPF thinks about the world, it becomes very natural, to the point where more traditional frameworks start to feel quite laborious by comparison. But yeah, it can be a bit of a battle to get to that point. |
|
|
This sounds like exactly what I need to do but I'm having some issues getting it to work. Any chance you couls post your XAML for your datatemplate so I can see how you are wiring up the itemssource to the list? Thanks,
Sean |
|
|
Nevermind got it working: Datatemplate in resources section: <DataTemplate x:Key="ListboxEditor"> Property Editor definition under <ms:PropertyGrid.Editors> <ms:TypeEditor EditedType="{x:Type mw:ListboxPropertyObject}" ListboxPropertyObject Class definition Public NotInheritable Class ListboxPropertyObject ' this class is used for items with a listbox
Sean |
|