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
|
I am a newbie and im trying to bind a collection to a combox within the datatemplate and was wondering how this would be acheived either in xaml or in the code-behind. I have the following code <DataTemplate x:Key='EditableQueueComboBox'><ComboBox Name="cmbQueue" SelectedValue="{Binding Path=Name}" SelectedValuePath="Name" DisplayMemberPath="Name" IsEditable="True"</ComboBox> </DataTemplate> ------ < ms:PropertyEditor PropertyName="Destination" EditorTemplate="{StaticResource EditableQueueComboBox}"/>I want to be able to bind a business object to the combobox. The business object is based on CSLA. I want to be able to bind the combox box when the propertygrid.selectedobjects has changed. The collection is going to call my DB something as follow Queue = new QueueCollection().Load() any help or direction would greatly be appreciated Thanks,Justin |
|
|
Hello Justin, Can you clarify what you are trying to achieve? Looking at your sample, I am guessing that the situation is something like this: 1. The object you are editing has a property Destination of type (say) string. 2. You want the user to be able to select the Destination value from a combo box instead of having to type it in. 3. The combo box is to be populated from... another business object I think? Is that right? Not sure how the "list of available destinations" object/property is related to the editee object if so. Is that correct? If so, have a look at http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=1297. The details will probably be a bit different -- specifically the ItemsSource binding will probably need to point to the "list of available destinations" object/property -- but the underlying idea of binding SelectedItem to Value and ItemsSource to the list should still be valid. Let us know if you need more information. |
|
|
ill try to explain it with a little more detail 1)Yeah I do have a property on the object being bound which is of type string 2) Yeah,want to be able to bind a business object collection of IList to the combobox 3)Thats correct the combo box is to be bounded to an IList object which is to be bound to the combobox in the code-behind, need to be able to call a function in my business object to be able to retrieve the data than bind it to the combobox. I hope this clarifies everything
|
|
|
Also not sure how to access the combobox in the cod-behind when its encapsualted within a datatemplate
|
|
|
The ObjectDataProvider might be what you need: <Window.Resources> where BusinessyThing is your CSLA class and GetDestinations() the method. This will obviously require a bit of tweaking if the list of destinations depends on the current object, i.e. if you need to pass the current object to the GetDestinations() method. Let me know if you run into problems with that and I'll have a look into it. |
|
|
Another option which might work more easily if you need to pass the current object into GetDestinations is to use a binding to UnderlyingObject: <ComboBox ... ItemsSource="{Binding UnderlyingObject, Converter={StaticResource GetDestinationsConverter}}" /> where GetDestinationsConverter looks something like this: public class GetDestinationsConverter : IValueConverter |
|
|
Thanks Ivan that worked well just one last thing, my combo box isEditable and I was trying to get the textchange event but no luck, is there a trick to be able to get the textchange event on the combobox as well as being able to select from a list. This is what i have so far <DataTemplate x:Key='EditableQueueComboBox'> <ComboBox Name="myComboBox" SelectedValue="{Binding Value}" ItemsSource="{Binding Value, Converter={StaticResource dropdown},ConverterParameter='Queue'}" SelectedValuePath="ID" DisplayMemberPath="Name" IsEditable="True" SelectionChanged="ComboBox_SelectionChanged" > </ComboBox></DataTemplate>< ms:PropertyEditor PropertyName="Destination" EditorTemplate="{StaticResource EditableQueueComboBox}"/>Thanks, Justin |
|
|
As far as I can tell from the documentation there isn't a TextChanged event on a ComboBox. Does SelectionChanged or something like that not fire for typing into the text area? I'm a bit surprised by that... Anyway, you might be able to intercept routed events from the contained TextBox by specifying: <ComboBox TextBoxBase.TextChanged="..." /> but I suspect this will not work because the ComboBox will swallow the event before it gets to your app code. You may be able to work around this by calling ComboBox.AddHandler(TextBoxBase.TextChangedEvent, myEventHandler, true) in code rather than setting up the event handler in XAML -- note the boolean parameter which says "I want to be notified even if the ComboBox has already handled the event internally." Please note I have not tested this! Another possible workaround is to handle the TextInput, KeyDown or PreviewKeyDown events -- again I have not tried this so you will need to do some experimenting. |
|