如何为错误创建类似的模板?

发布于 2024-12-29 00:42:39 字数 146 浏览 4 评论 0原文

我在几个网站上看到使用 ErrorTemplate 的样式发布其应用程序的一些图像,如下所示:

在此处输入图像描述

你知道我在哪里可以找到它吗?

I've seen in several sites where publish some images of their applications using a style for ErrorTemplate like this:

enter image description here

Do you know where can I find it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

屌丝范 2025-01-05 00:42:39

我刚刚制作了一个,做了一些修改,但它可以在我的 WPF 测试应用程序中运行(使用 .Net 4.0)。我实际上想要为我正在开发的应用程序提供类似的东西,所以你的问题是一个方便的借口。 =)

此代码使用 Validation.ErrorTemplate 附加属性创建一个 ControlTemplate,它设置一个红色边框来勾勒出经过验证的控件,然后设置一个 Popup code> 包含控件的错误消息。我必须从已验证控件的 ToolTip 属性中获取错误消息,因为模板内的 TextBox 似乎无法访问 Validation类本身。

当经过验证的控件失去焦点时,弹出错误消息将关闭,并在再次获得焦点时重新出现(如果存在错误)。

这是一个屏幕截图:
Screenshot

这是要点代码: https://gist.github.com/1672789

我愿意接受任何人提出的任何意见或改进。

I just whipped one up, took a little tinkering but it works in my WPF test application (using .Net 4.0). I actually wanted something like this for an application I'm working on, so your question was a convenient excuse to make one. =)

This code uses the Validation.ErrorTemplate attached property to create an ControlTemplate that sets up a red border to outline the validated control, and then a Popup that contains the error message for the control. I had to get the error message from the validated control's ToolTip property because the TextBox inside the template didn't seem to have access to the Validation class itself.

The popup error message closes when the validated control looses focus, and reappears (if there is an error) when it gains focus again.

Here's a screenshot:
Screenshot

Here's the gist code: https://gist.github.com/1672789

I'm open to any comments or improvements anyone would offer.

别想她 2025-01-05 00:42:39

这看起来很像 Adorner
这个想法是在控件上方/附近绘制一些其定义的东西,该控件也不受应用于场景的变换的影响。

例如,您可以在 TextBoxStyle 中定义装饰器。

像这样的东西(伪代码):

<Style TargetType="{x:Type TextBox}">
     <Setter Property="Template">
                <Setter.Value>
                   <ControlTemplate TargetType="{x:Type ScrollViewer}">
                       ........
                       ........
                       <AdornerDecorator Grid.Column="0" Grid.Row="0">
                           .........
                           .........
                       </AdorenrDecorator>
                    </ControlTemplate>
                </Setter.Value>
     </Setter>
</Style>

完整的示例(对于ScrollViewer,但IDE是相同的)可以找到此处

This looks much like Adorner.
The idea is to draw something above/near the control where its defined which is not also affected by transformations applied to scene.

For example you can define a Adorner in Style of your TextBox.

Something like this (a pseudocode):

<Style TargetType="{x:Type TextBox}">
     <Setter Property="Template">
                <Setter.Value>
                   <ControlTemplate TargetType="{x:Type ScrollViewer}">
                       ........
                       ........
                       <AdornerDecorator Grid.Column="0" Grid.Row="0">
                           .........
                           .........
                       </AdorenrDecorator>
                    </ControlTemplate>
                </Setter.Value>
     </Setter>
</Style>

A complete example (for ScrollViewer, but the ides is the same) can find here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文