我无法对包含日期选择器和文本块的 WPF 数据网格模板列设置验证
数据网格模板列包含日期选择器和文本块,用于编辑的日期选择器和用于显示的文本框。 我尝试在此列上应用样式来验证它,但它仅应用于日期选择器而不是文本块:
<Style x:Key="DateEditStyle" TargetType="{x:Type my:DatePicker}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="Plase check the data in the cell"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="TextBlockEditStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="Plase check the data in the cell"/>
</Trigger>
</Style.Triggers>
</Style>
<my:DataGridTemplateColumn x:Name="SrvDateCol" Header="Date" Width="100">
<my:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<my:DatePicker SelectedDate="{Binding srvdate,StringFormat=d, ValidatesOnExceptions=True}"
SelectedDateChanged="DatePicker_SelectedDateChanged"
Style="{StaticResource DateEditStyle}"></my:DatePicker>
</DataTemplate>
</my:DataGridTemplateColumn.CellEditingTemplate>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding srvdate,StringFormat=d,ValidatesOnExceptions=True}"/>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
当我在单元格中输入错误日期时,样式效果很好,但是当我离开它时,样式消失了,并且细胞恢复到原来的状态。那么如何在 TextBlock 上应用样式呢? 我希望我的问题很清楚。
There is datagrid template column contains datepicker and textblock, the datepicker for editing and the textbox for showing.
I try to apply a style on this column to validate it, but it just be applied on the datepicker not the textblock:
<Style x:Key="DateEditStyle" TargetType="{x:Type my:DatePicker}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="Plase check the data in the cell"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="TextBlockEditStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="Plase check the data in the cell"/>
</Trigger>
</Style.Triggers>
</Style>
<my:DataGridTemplateColumn x:Name="SrvDateCol" Header="Date" Width="100">
<my:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<my:DatePicker SelectedDate="{Binding srvdate,StringFormat=d, ValidatesOnExceptions=True}"
SelectedDateChanged="DatePicker_SelectedDateChanged"
Style="{StaticResource DateEditStyle}"></my:DatePicker>
</DataTemplate>
</my:DataGridTemplateColumn.CellEditingTemplate>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding srvdate,StringFormat=d,ValidatesOnExceptions=True}"/>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
When I enter error date in the cell, the style works good, but when I leave it the style disappeares, and the cell return back to its original state. So how to apply the style on the TextBlock also??
I hope my question is clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论