问题描述
我们希望使用 用户体验指南 来自微软.我发现了一些使用来自 Windows 窗体的本机代码的示例,但本机代码需要组件的句柄,这对于 WPF 应用程序来说有点困难,因为它不遵循相同的概念.
We would like to use balloon messages as described in the UX Guide from Microsoft. I found some samples which uses native code from Windows Forms, but the native code requires a handle to the component which a bit difficult for a WPF application since it doesn't follow the same concept.
我发现了一些使用 WPF 的装饰器机制的示例代码,但我仍然没有确信这是 WPF 应用程序最简单的方法.可能的实现是围绕工具提示实现装饰器吗?
I found some sample code which uses WPF's decorator mechanism, but I'm still not convinced that this is the easiest approach for WPF application. Could a possible implementation be to implement a decorator around a tooltip?
我所拥有的具体案例是一个包含多个文本框的表单,这些文本框需要输入验证并就可能的错误输入值发出通知——这似乎适合气球消息.
The concrete case I have is a form with several text boxes which need input validation and notification on possible wrong input values - something which seems appropriate for balloon messages.
是否有我应该注意的 WPF 下为此用例构建的商业或开源控件?
Is there a commercial or open source control built for this use case under WPF that I should be aware of?
推荐答案
我最终在装饰层中放置了一个 TextBlock:
I ended up putting a TextBlock in the adorner layer:
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Vertical">
<Border>
<AdornedElementPlaceholder x:Name="adorner"/>
</Border>
<TextBlock
Height="20" Margin="10 0" Style="{StaticResource NormalColorBoldWeightSmallSizeTextStyle}"
Text="{Binding ElementName=adorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
我还使用了每个 WPF 示例中所示的工具提示:
I also used the tooltip as shown in every WPF examples out there:
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}">
</Setter>
</Trigger>
</Style.Triggers>
不是最优的(真的很像一个气球消息控件),但足以满足我们的需要.
Not optimal (would really like a Balloon Message control), but works good enough for the need we have.
这篇关于如何在 WPF 应用程序中实现气球消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!