How to handle exception in Value converter so that custom error message can be displayed

后端 未结 3 468
一生所求
一生所求 2020-12-15 19:36

I have a textbox that is bound to a class with a property of type Timespan, and have written a value converter to convert a string into TimeSpan.

If a non number is

3条回答
  •  时光取名叫无心
    2020-12-15 20:06

    I would use a ValidationRule for that, this way the converter can be sure that the conversion works since it only is called if validation succeeds and you can make use of the attached property Validation.Errors which will contain the errors your ValidationRule creates if the input is not the way you want it.

    e.g. (note the tooltip binding)

    
        
            
        
        
            
                
                    
                
                
                    
                
            
        
    
    

    screenshot

提交回复
热议问题