如何实现在WPF应用程序气球消息 [英] How to implement Balloon message in a WPF application

查看:233
本文介绍了如何实现在WPF应用程序气球消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想用气球消息作为 UX指南描述。我发现了一些样本,使用本机code从Windows窗体,但本土code要求的句柄,这有点困难的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.

我发现了一些样品code 它使用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应用程序气球消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆