1
votes

I am trying to bind to a combobox text with the IsEditable property set to true. I have a property in my viewmodel which is bound to the text.

I want to validate on the text being typed in the text of the combobox, and restrict some values that the user is typing in. So some will be allowed, and some not, and these need to set the combobox back to its old value.

I do this in the view model and I have tried setting my text property in my view model explicity to the old value or just ignoring the change and raising that the property has been changed, but for the life of me it will not refresh the text back to the old value.

Is this because the combobox is editable, and it has the text caret and focus somewhere in the text of the combobox.

Basically, I want it to refresh back to the previous text when I restrict some typing in the combobox during in editing. Anyone have any ideas to reset the text back to its old value through the ViewModel. Thanks in advance!

3

3 Answers

1
votes

Thanks for your replies. But I could never get it to work instead, I made my own UserControl which comprises a textbox overlayed over a combobox, and manipulate those two controls to meet my needs. A long way to go to solve a simple problem, but it works in the end.

0
votes

Is the viewmodel property you are binding to created as a DependencyProperty? This is probably the problem you are facing Two-way binding in WPF

If you don't want to create a Dependency property then you need to implement INotifyProperty changed and manually force the update in the Property changed event.

0
votes

I think this is because of a 'bug' in WPF not refreshing the UI if you change the value of a property in the setter. You can workaround it by implementing an IdentityConverter that force the UI to refresh as per this arcticle.