我创建了一个自定义错误模板来显示验证错误.这是我的XAML:
<Style targettype="Control" x:Key="myErrorTemplate"> <Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate> <DockPanel LastChildFill="True"> <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="26" FontWeight="Bold" Text=" !" Margin="0,-8,0" /> <Border> <AdornedElementPlaceholder Name="myControl" /> </Border> </DockPanel> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors)[0].ErrorContent}" /> </Trigger> </Style.Triggers> </Style>
当发生验证错误时,这将在TextBox附近放置一个感叹号.当鼠标悬停在TextBox上时,此模板将显示错误工具提示.当我将鼠标悬停在感叹号(文本块)上时,我还想显示工具提示.我该如何实现这一目标?
解决方法
试试这个:
<TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="26" FontWeight="Bold" Text=" !" Margin="0,0" > <TextBlock.Style> <Style targettype="TextBlock"> <Style.Triggers> <DataTrigger Binding="{Binding Path=(Validation.HasError),RelativeSource={RelativeSource TemplatedParent}}" Value="True"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource TemplatedParent},Path=(Validation.Errors)[0].ErrorContent}" /> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。