4

I have a combo box (in my wpf-mvvm app). I have set IsEditable = true. But the "property changed event" is getting fired when I start typing.

How can I set UpdateSourceTrigger = Propertychanged here ?

Also..I need to call a validation function if user has entered new value ( i mean other than those available in list ..using edit functionality).

Any help will be appreciated.

    <ComboBox ItemsSource="{Binding Path = PlanTypeBasedContractNumberList }" Width="90" IsEditable="True"  
SelectedValue="{Binding GeneralCharacteristicsDataContext.ContractNumber.Value}">
                            </ComboBox>
Sam
  • 7,252
  • 16
  • 46
  • 65
Relativity
  • 6,690
  • 22
  • 78
  • 128

1 Answers1

8

In an editable ComboBox, the SelectedItem and SelectedValue properties refer to the Popup items, not the editable item. Once you start typing, the SelectedItem becomes "unselected" and that's why the event fires.

To bind to the value of the TextBox of the ComboBox, use the Text property:

<ComboBox IsEditable="True" Text="{Binding Path=..., UpdateSourceTrigger=...}">
Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
  • what you mean by "Text box of combobox" ? The textbox in item template ? Could you give me a sample code ? – Relativity Jan 23 '11 at 02:22
  • When you use `IsEditable` with `ComboBox`, you get a composite control that contains a `Popup` and a `TextBox` as a result of the `ControlTemplate`. It's the thing you type into. The sample code I gave is all you need. – Rick Sladkey Jan 23 '11 at 02:29
  • But in the above sample, where is the SelectedValue/SelectedItem ?...I mean, when i select another item from the list..Text will not be set & Only Selecteditem/value will be set, right ? – Relativity Jan 23 '11 at 02:37
  • If an item is selected from the `Popup`, `Text` will contain its text, just like you see on the screen. – Rick Sladkey Jan 23 '11 at 02:40
  • I'm catching a property changed event....on change of this selected item..i have to do some actions. With the above code..my text's porperty chnge is called...but not on already existing list's selected value change – Relativity Jan 23 '11 at 02:51
  • Then what you want is the code you presented. See the first section of my answer. – Rick Sladkey Jan 23 '11 at 02:55