如何为错误创建类似的模板?
我在几个网站上看到使用 ErrorTemplate 的样式发布其应用程序的一些图像,如下所示:
你知道我在哪里可以找到它吗?
I've seen in several sites where publish some images of their applications using a style for ErrorTemplate like this:
Do you know where can I find it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚制作了一个,做了一些修改,但它可以在我的 WPF 测试应用程序中运行(使用 .Net 4.0)。我实际上想要为我正在开发的应用程序提供类似的东西,所以你的问题是一个方便的借口。 =)
此代码使用
Validation.ErrorTemplate
附加属性创建一个ControlTemplate
,它设置一个红色边框来勾勒出经过验证的控件,然后设置一个Popup
code> 包含控件的错误消息。我必须从已验证控件的ToolTip
属性中获取错误消息,因为模板内的TextBox
似乎无法访问Validation
类本身。当经过验证的控件失去焦点时,弹出错误消息将关闭,并在再次获得焦点时重新出现(如果存在错误)。
这是一个屏幕截图:

这是要点代码: 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 anControlTemplate
that sets up a red border to outline the validated control, and then aPopup
that contains the error message for the control. I had to get the error message from the validated control'sToolTip
property because theTextBox
inside the template didn't seem to have access to theValidation
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:

Here's the gist code: https://gist.github.com/1672789
I'm open to any comments or improvements anyone would offer.
这看起来很像 Adorner。
这个想法是在控件上方/附近绘制一些其定义的东西,该控件也不受应用于场景的变换的影响。
例如,您可以在
TextBox
的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 yourTextBox
.Something like this (a pseudocode):
A complete example (for
ScrollViewer
, but the ides is the same) can find here