Reputation: 20414
I've got a ComboBox that contains an item for each FilterViewModel that is defined in my application. Each FilterViewModel has a DisplayName property that contains the name of the filter. The currently selected filter instance is saved in the SelectedFilter property.
I want the user to be able to select an existing item from the dropdown list, but also change the selected filter's name in the text box. Entering another name must not change the item selection. There is always one filter selected, it can never be that no filter is selected.
Here's the XAML code:
<ComboBox
IsEditable="True" IsTextSearchEnabled="False"
ItemsSource="{Binding Filters}"
SelectedItem="{Binding SelectedFilter}"
DisplayMemberPath="DisplayName"/>
I can't find a TextChanged event for the ComboBox, and simply letting it as-is doesn't change the selected item's bound text property, DisplayName (I'd have expected that).
What can I do to get it work as described above?
The background is that this ComboBox is used in my application's settings dialog where the filters can be managed (created, duplicated, renamed, deleted) and their filter conditions can be edited. I'd like to save me the extra button and window or TextBox to rename a filter but offer that function directly in-place. You see the filter name, just click on it and type to change it. But I'd also like to use the ComboBox to have a drop-down selection menu to switch filters.
Upvotes: 2
Views: 3005
Reputation: 33384
This should allow you to change DisplayName
of SelectedFilter
without changing SelectedFilter
itself:
<ComboBox
ItemsSource="{Binding Filters}"
SelectedItem="{Binding SelectedFilter}"
DisplayMemberPath="DisplayName"
Text="{Binding SelectedFilter.DisplayName, Mode=TwoWay}"
IsEditable="True"
IsTextSearchEnabled="False"/>
Upvotes: 3