Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF TextBox StringFormat无法与PropertyChanged一起使用_Wpf_Xaml_Textbox_String Formatting - Fatal编程技术网

WPF TextBox StringFormat无法与PropertyChanged一起使用

WPF TextBox StringFormat无法与PropertyChanged一起使用,wpf,xaml,textbox,string-formatting,Wpf,Xaml,Textbox,String Formatting,我有个问题。我需要在所有文本框中设置双格式值 当你在这里输入一些东西时,失去焦点后,它将被格式化 <TextBox Text="{Binding ABC, StringFormat='{}{0:N}'}" /> 添加此属性已更改的UpdateSourceRigger时会出现问题。那么它将永远不会被格式化 <TextBox Text="{Binding ABC, UpdateSourceTrigger=PropertyChanged, StringFormat='{}{0:N

我有个问题。我需要在所有文本框中设置双格式值

当你在这里输入一些东西时,失去焦点后,它将被格式化

<TextBox Text="{Binding ABC, StringFormat='{}{0:N}'}"  />
添加此属性已更改的UpdateSourceRigger时会出现问题。那么它将永远不会被格式化

<TextBox Text="{Binding ABC, UpdateSourceTrigger=PropertyChanged, StringFormat='{}{0:N}'}"  />
为什么呢?有没有办法解决这个问题?在XAML中,最好试试这个

<TextBox x:Name="test" Text="{Binding MyName, UpdateSourceTrigger=Explicit,StringFormat='{}{0:N}'}" TextChanged="test_TextChanged" Width="100" Height="30" />


 private void test_TextChanged(object sender, TextChangedEventArgs e)
    {
        BindingExpression exp = test.GetBindingExpression(TextBox.TextProperty);
        exp.UpdateSource(); 
    }
试试这个