WPF - 使用样式触发器设置自定义工具提示
我正在尝试根据属性 HasValidationError 将工具提示显示到堆栈面板。
<Style TargetType="StackPanel" x:Key="stackstyle">
<Style.Triggers>
<DataTrigger Binding="{Binding HasValidationError}" Value="True">
<Setter Property="ToolTip">
<Setter.Value>
<Binding Path="DisplayError"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
该代码运行良好。但它在黄色背景下显示工具提示(与普通工具提示一样)。我需要对其进行自定义以更改并包含图像。为此,
<Style TargetType="StackPanel" x:Key="stackstyle">
<Style.Triggers>
<DataTrigger Binding="{Binding HasValidationError}" Value="True">
<Setter Property="ToolTip">
<Setter.Value>
<StackPanel>
<!-- Have to add image and other decorations here -->
<TextBlock Text = "{Binding DisplayError}"/>
</StackPanel>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
将 StackPanel 添加到 .请帮我解决。
I am trying to display tool tip to a stack panel based on property HasValidationError.
<Style TargetType="StackPanel" x:Key="stackstyle">
<Style.Triggers>
<DataTrigger Binding="{Binding HasValidationError}" Value="True">
<Setter Property="ToolTip">
<Setter.Value>
<Binding Path="DisplayError"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
The code works fine. But it displays the tooltip under yellow background ( as normal tooltip). I need to customize it to change and include image. For that,
<Style TargetType="StackPanel" x:Key="stackstyle">
<Style.Triggers>
<DataTrigger Binding="{Binding HasValidationError}" Value="True">
<Setter Property="ToolTip">
<Setter.Value>
<StackPanel>
<!-- Have to add image and other decorations here -->
<TextBlock Text = "{Binding DisplayError}"/>
</StackPanel>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
It shows error when adding StackPanel to the . Please help me in solving.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么会失败,但您可以通过将 ToolTip 设置为资源来解决此问题:
或者
此外,您拥有的代码将按照 .NET 4 中编写的方式工作,因此该错误已得到修复。
I don't know why that fails, but you can work around it by making the ToolTip a resource:
or
Also, the code you have will work as written in .NET 4, so the bug has been fixed.