Wpf中的十进制绑定问题 [英] Decimal Binding Issue in Wpf
问题描述
我有bsp>文本框。并将十进制属性绑定到文本框。参见
I have Text Box. And binding decimal property to text box. see
<TextBox Grid.Row="2" Grid.Column="1" Margin="0,8,0,0" Text="{Binding QuoteModel.PWRate,
UpdateSourceTrigger = PropertyChanged}" IsReadOnly =" {Binding QuoteModel.IsPWRateReadOnly}" >
< ie:Interaction.Triggers>
< ie:EventTrigger EventName =" TextChanged">
< ie:InvokeCommandAction Command =" {Binding PWTextChangeCommand}" />
< / ie:EventTrigger>
< / ie:Interaction.Triggers>
< / TextBox>
UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding QuoteModel.IsPWRateReadOnly}" > <ie:Interaction.Triggers> <ie:EventTrigger EventName="TextChanged"> <ie:InvokeCommandAction Command="{Binding PWTextChangeCommand }" /> </ie:EventTrigger> </ie:Interaction.Triggers> </TextBox>
当我们输入12.23然后它需要1223或一段时间它需要12.23。
When we typing 12.23 then its take 1223 or some time it's taking 12.23.
当我们使用 UpdateSourceTrigger =已明确
时,此属性值不会更改意味着更改的属性不会触发。
When we are using UpdateSourceTrigger=Explicit
also this not changing value of property means property changed does not fire.
这是什么解决方案?这个问题发生在int或十进制而不是字符串。
what is the solution of this? This issue occurring with int or decimal not with string.
如果在显式的情况下如何更新源我们实际上正在使用MVMV?
And how to update source in case of explicit actually we are using MVMV?
谢谢
推荐答案
一个简单的方法是使用
One simple approach is to use
, UpdateSourceTrigger=LostFocus
这当然是默认值。
或者,您可以尝试使用KeepTextBoxDisplaySynchronizedWithTextProperty
Alternatively, you could experiment with KeepTextBoxDisplaySynchronizedWithTextProperty
https://msdn.microsoft.com/en-us/library/system.windows.frameworkcompatibilitypreferences.keeptextboxdisplaysynchronizedwithtextproperty(v = vs.110 ).aspx
https://msdn.microsoft.com/en-us/library/system.windows.frameworkcompatibilitypreferences.keeptextboxdisplaysynchronizedwithtextproperty(v=vs.110).aspx
public MainWindow()
{
FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;
InitializeComponent();
}
在应用任何内容之前设置在主窗口中或在应用生命周期的早期设置类似于
Set in mainwindow before anything is loaded or somewhere similarly early on in your app's lifecycle
这篇关于Wpf中的十进制绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!