Binding to double field with validation

前端 未结 6 961
时光说笑
时光说笑 2020-12-30 04:13

I\'m trying to bind TextBox to double property of some object with UpdateSourceTrigger=PropertyChanged. The goal is to immediately dur

6条回答
  •  被撕碎了的回忆
    2020-12-30 04:15

    The behavior of binding float values to a textbox has been changed from .NET 4 to 4.5. With .NET 4.5 it is no longer possible to enter a separator character (comma or dot) with ‘UpdateSourceTrigger = PropertyChanged’ by default.

    Microsoft says, this (is) intended

    If you still want to use ‘UpdateSourceTrigger = PropertyChanged’, you can force the .NET 4 behavior in your .NET 4.5 application by adding the following line of code to the constructor of your App.xaml.cs:

    public App()  
    {
        System.Windows.FrameworkCompatibilityPreferences
                   .KeepTextBoxDisplaySynchronizedWithTextProperty = false;   
    }
    

    (Sebastian Lux - Copied verbatim from here)

提交回复
热议问题