DataGridTextColumn不允许小数

DataGridTextColumn不允许小数

本文介绍了WPF Datagrid DataGridTextColumn不允许小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在DataGridTextColumn中输入十进制值.如果UpdateSourceTrigger = PropertyChanged,则下面的链接建议我们无法输入十进制值.

I am not able to enter decimal values in DataGridTextColumn. Below link suggest that we cannot enter decimal values if UpdateSourceTrigger = PropertyChanged.

WPF DataGridTextColumn绑定不接受小数位

但是我的要求是我必须保持UpdateSourceTrigger = PropertyChanged.

But my requirement is that I have to keep UpdateSourceTrigger = PropertyChanged.

请提出建议.

以下是我的Datagrid的代码段:

Below is the code snippet for my Datagrid:

  <DataGrid x:Name="MyDataGrid" HorizontalAlignment="Left" CanUserResizeColumns="True" VerticalAlignment="Stretch" ItemsSource="{Binding MyDataCollectionListView, Mode=TwoWay}"
      SelectionMode="Extended" IsSynchronizedWithCurrentItem="True" SelectionUnit="Cell">
     <DataGrid.Columns>
      <DataGridTextColumn x:Name="ColMyDataGrid" Header="Price" Binding="{Binding Path=Price, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, Converter={StaticResource    ZeroToEmptyConverter}}" >
  <DataGridTextColumn.ElementStyle>
    <Style TargetType="TextBlock">
      <Setter Property="TextAlignment" Value="Right" />
       <Setter Property="Background" Value="#BEFAC4"/>
    </Style>
  </DataGridTextColumn.ElementStyle>
 </DataGridTextColumn>
</DataGrid.Columns>

推荐答案

UpdateSourceTrigger = LostFocus然后允许自动删除小数点

UpdateSourceTrigger=LostFocus then allow remove decimal point automatically

这篇关于WPF Datagrid DataGridTextColumn不允许小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 00:23