WPF Datagrid DataGridTextColumn does not allow decimal

孤者浪人 提交于 2020-01-16 15:21:24

问题


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

WPF DataGridTextColumn binding doesn't accept decimals

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

Please suggest.

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>


回答1:


UpdateSourceTrigger=LostFocus then allow remove decimal point automatically



来源:https://stackoverflow.com/questions/24628058/wpf-datagrid-datagridtextcolumn-does-not-allow-decimal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!