0

I have a combobox with a simple binding:

SelectedValue="{Binding Path=SomeValue, Mode=TwoWay}

The problem is that SomeValue is sometimes a string not parsable to int. And I get "System.FormatException: Input string was not in a correct format." as soon as I set the ItemsSource.

First question: how to handle the exception since I get a error message box. Second question: can I show kind of a validation error to the user?

Attention: the source of the problem comes from the view model data source so I don't think it has anything to classical validation patterns.

Valentin
  • 717
  • 10
  • 21
  • read thath https://stackoverflow.com/questions/4902039/difference-between-selecteditem-selectedvalue-and-selectedvaluepath - you have to your way beacause i am not sure what you want... – GCamel Sep 06 '17 at 11:55
  • What is your ComboBox bound to? The types should match. Where are you getting an "error message box"? – mm8 Sep 06 '17 at 12:15
  • @Valentin So since you set your `SomeValue` from ViewModel, you can use Double.TryParse instead of Double.Parse. – sTrenat Sep 06 '17 at 13:01

1 Answers1

0

Create a dummy converter and put it into the debugger and put a breakpoint into it. It will become obvious what is wrong, types will be different. Use Snoop to determine the error logs by holding control shift and selecting that element and look under SelectedValue property.

RJ Thompson
  • 126
  • 7