C# DataGridTextColumn 绑定数字字段的自定义错误提示信息
```csharp <DataGridTextColumn Width="*" Binding="{Binding OwnerAmount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="出资金额(万元)"> <DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="TextWrapping" Value="Wrap" /> </Style> </DataGridTextColumn.ElementStyle> <DataGridTextColumn.EditingElementStyle> <Style TargetType="TextBox"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="True"> <Setter Property="ToolTip" Value="请输入有效的数字" /> </Trigger> </Style.Triggers> </Style> </DataGridTextColumn.EditingElementStyle> </DataGridTextColumn> ```
在上述的代码中,我们使用TextBox作为EditingElementStyle的TargetType,并添加了一个Trigger,当Validation.HasError为True时,设置ToolTip为自定义的提示信息"请;输入有效的数字"。;这样,当输入错误的值时,将会在输入框的周围显示提示信息。你可以根据需要修改提示信息的内容和样式。
原文地址: https://www.cveoy.top/t/topic/p3rZ 著作权归作者所有。请勿转载和采集!