问题
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