SmallestWish
SmallestWish

Reputation: 115

Combobox: Get text and selected item in mvvm way

The combobox is editable so user can also write. I have two usecases:

  1. Get the text from combobox in a Lostfocus way, when user writes something in the box and when he presses "Tab" then I want the text from the combobox and I add the value in the itemsSource list.
  2. When the users makes the selection from the combobox dropdown, I want that selected item as soon he selects it and this time I dont want to have it in Lostfocus manner but somewhat like PropertyChanged way.

I tried the code which is given below:

 <ComboBox Margin="3" x:Name="Combobox" SelectedItem="{Binding SelectedPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Text="{Binding PathLocation, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True}" IsTextSearchEnabled="True" VerticalContentAlignment="Center" ItemsSource="{Binding SelectedPaths}" IsEditable="True" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Stretch"/>

Things worked fine for the first time when the application starts but after some interactions the problem arises. When the user starts typing in the combobox the SelectedItem property of combobox triggers which is contrary to what I want in the first use case.

In short: when the user writes something in the combobox I want to have it in a Lostfocus manner and when he makes the selection from the dropdown of combobox I want to have it in a PropertyChanged manner.

Let me know if more details are required.

Upvotes: 0

Views: 258

Answers (1)

SmallestWish
SmallestWish

Reputation: 115

I removed the "IsTextSearchEnabled" property but it also didnt work then I came to know that "IsTextSearchEnabled" property of Comobobox is by default true, which is causing some values suggested by the combobox are setting in my properties. As soon as I made the "IsTextSearchEnabled" to false, it is working fine.

Upvotes: 0

Related Questions