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’m implementing a feature in a rather complex way, and I was wondering if there is a more straightforward approach. In order to get the grid to display ObservableCollection elements in a ComboBox , rather than the default collection of elements, I define a “dummy” property as a int, then define a ComboBox property editor that binds ItemsSource to an ObservableCollection property that’s in a global resource class (ObjectDataProvider). Then I have another Non-browsable property to contain the ComboBox SelectedItem. In order to get the SelectedItem into the Non-browsable property, I respond to the ComboBox SelectionChanged event, and publish an event I have defined with a delegate in the property editor class. The class that contains the dummy and Non-browsable properties subscribes to the event and sets the Non-browsable property to the ComboBox Selected Item when it receives notification.Instead of this convoluted event system, I would like to bind the ComboBox SelectedItem property to my Non-browsable property. But I don’t know how to specify that property in another property’s editor.Any thoughts?Thanks.
|
|
|
Just to step back from the implementation for a moment, I am not quite sure which of the following two scenarios you're trying to implement (at the requirements/behaviour level -- ignoring the details of dummy and non-browsable properties for now). Scenario 1 * You have a property of collection type * Instead of having the collection appear as an expandable list, you want it to appear as a single, non-expandable row, with the values appearing in a combo box * The combo box is NOT being used to select a value -- it is just a compact way of presenting the collection elements Scenario 2 * You have a property of string (?) type * You want the user to select the value of this property from a drop-down list instead of typing it * The application has to be able to define the set of permitted values in resources (and the set of permitted values may change over time?) I *think* you are describing the second scenario but I just wanted to be sure before I start suggesting things! |
|
|
Actually, it's a mix of your 2 scenarios. Here are my requirements: * You have a property of collection type * Instead of having the collection appear as an expandable list, you want it to appear as a single, non-expandable row, with the values appearing in a combo box * The combo box IS being used to select a value * The application has to be able to define the set of permitted values in resources (and the set of permitted values may change over time) Thanks alot for looking at this.
|
|
|
I am probably having a bit of a dense day here: I think I understand your scenario but I am still not 100% sure, so let me state it back to you. * There are actually *two* properties involved here. One of these properties is a collection, the other is a value. I will assume for simplicity that these are strings, and will call them Strings and SelectedItem. * You want to display the contents of the Strings collection in a combo box. * When the user selects a value in the combo box, that sets the value of the SelectedItem property. If this is correct, then what you want to do is put the combo box editor on the SelectedItem property (because that's the property whose value is being operated on), *NOT* on the Strings collection. (You would probably make the Strings collection non-browsable.) The editor can then be defined as follows (ignoring aesthetics): <DataTemplate x:Key="cb"> Note the use of UnderlyingObject to get to the object whose properties are being edited. From there we can navigate to its Strings collection to serve as an ItemsSource for the combo box. If the Strings collection is updated, the drop-down will reflect these changes. Even if I haven't understood the exact scenario, it may be that the ability to get to UnderlyingObject will help you to unlock the issue of "binding to one property in another property's editor." See the ObjectWrapper and ObjectWrapper<T> classes for more information. If not, please let me know where I'm misunderstanding and I'll have another go! |
|
|
That's exactly what I wanted. Thanks! |
|
|
I have used this method to solve a similar problem, however I'm running into a strange issue. I have an interface where you can select an item, and then revisit that interface at a later time to make changes. The saved value from the SelectedItem binding doesn't seem to be displaying, despite it being present in the bound property. Here is how I have it implemented: <DataTemplate x:Key="comboBoxTemplate"> <DataTemplate x:Key="listEditorTemplate"> The editor declaration on the property grid: <ms:PropertyEditor The Selection property is a custom type that implements INotifyPropertyChanged correctly. TheList property is a non-browsable List<T> of that custom type. Any ideas about what I'm doing wrong. I'm not a master of data binding, so I'm likely missing something important. Thanks |
|
|
That looks okay. And you say the Selection property is being updated correctly in the source object, just not appearing in the ComboBox? I wonder if this is something to do with the way the ComboBox is trying to render the custom type in its text area? Could you post a small, complete repro case so I can take a look at this for you? You can attach files via the Options tab. Thanks! |
|