我有一个 DataGrid,其列绑定到 ViewModel 十进制属性。
当从 ViewModel 添加值时会显示十进制值,但是当我编辑同一个单元格并删除内容然后添加时,该单元格不接受.期间。那我该如何编辑单元格。
<DataGrid Name="dgSales" Height="300" Margin="0,3,0,0" IsSynchronizedWithCurrentItem="True" SelectedItem="{Binding SelectedItem,Converter={StaticResource ignoreNewItemPlaceHolderConverter}}" ItemsSource="{Binding StockList,UpdateSourceTrigger=PropertyChanged}" ToolTip="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}" GotKeyboardFocus="dgSales_GotKeyboardFocus" CurrentCellChanged="dgSales_CurrentCellChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="S No." Width="SizeToCells" MinWidth="60" Binding="{Binding SNo}" IsReadOnly="True" />
<DataGridTemplateColumn Header="Stock Name" Width="280">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding StockName}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Width="280" Name="cmbStock" ItemsSource="{Binding Path=Stocks}" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" ></ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Unit Price" Width="SizeToCells" MinWidth="80" Binding="{Binding UnitPrice,UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Header="Unit" Width="SizeToCells" MinWidth="80" Binding="{Binding Unit}" IsReadOnly="True"/>
<DataGridTextColumn Header="Quantity" Width="SizeToCells" MinWidth="80" Binding="{Binding Quantity,UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Header="Discount" Width="SizeToCells" MinWidth="80" Binding="{Binding Discount,UpdateSourceTrigger=PropertyChanged}"/>
<DataGridTextColumn Header="Amount" Width="SizeToCells" MinWidth="100" Binding="{Binding Amount,StringFormat=\{0:n2\}}" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>