当我们在验证 controlTemplate 中使用 AdornedElementPlaceholder 时,它究竟做了什么? [英] What does AdornedElementPlaceholder exactly do when we use it in validation controlTemplate?

查看:32
本文介绍了当我们在验证 controlTemplate 中使用 AdornedElementPlaceholder 时,它究竟做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了几篇展示

用法的文章和例子之后<块引用>

装饰元素占位符

我仍然很困惑,它包含在 xaml 验证中的确切功能是什么?

解决方案

如果您使用验证,您需要向用户显示验证失败的地方(和内容),这就是 AdornedElementPlaceholder 发挥作用的地方.它是一个与您正在验证的 UIElement 大小完全相同的占位符.

假设您正在验证 TextBox 上的用户输入,并希望在验证失败时在 TextBox 周围显示一个红色框.为 TextBox 定义一个 ValidationRule 和一个验证模板.如果 ValidationRule 失败,则 Validation.ErrorTemplate 将显示在您的 TextBox 上.在模板中,AdornedElementPlaceholder 告诉框架在 UI 上放置模板的位置.在我们的例子中,模板可能如下所示:

<Border BorderBrush="红色" BorderThickness="1"><AdornedElementPlaceholder/></边框></控制模板>

您应该阅读这篇文章.>

After going through several articles and examples showing usage of

AdornedElementPlaceholder

i am still confused that what is the exact functionality it incorporates to xaml validation?

解决方案

If you use Validations you need to show the user where (and what) failed to validated and that’s where AdornedElementPlaceholder comes into play. It is a Placeholder that has exactly the same size of the UIElement you’re validating.

Let’s say you’re validating user input on a TextBox and want to show a red box around the TextBox when the validation fails. Define a ValidationRule and a validation template for the TextBox. If the ValidationRule fails, then the Validation.ErrorTemplate is shown on your TextBox. Inside the template the AdornedElementPlaceholder tells the Framework where to place your template on the UI. In our case the template might look like this:

<ControlTemplate>
    <Border BorderBrush="Red" BorderThickness="1">
        <AdornedElementPlaceholder />
    </Border>
</ControlTemplate> 

You should read this article.

这篇关于当我们在验证 controlTemplate 中使用 AdornedElementPlaceholder 时,它究竟做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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