自定义验证错误模板不符合ZIndex [英] Custom validation error template not respecting ZIndex

查看:41
本文介绍了自定义验证错误模板不符合ZIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图定义为DataTemplate(用于 OrderEntryViewModel),其中的菜单,ContentPresenter和Expander位于3行网格内。 ContentPresenter的内容绑定到另一个viewModel OrderViewModel(为此提供了另一个DataTemplate定义的视图)。扩展器的ZIndex为99,因此在向上扩展时,它将在所有其他控件(即ContentPresenter)上扩展。



除了ContentPresenter的内容(OrderViewModel)出现数据错误外,这一切都可以按预期方式进行...我的OrderView在带有无效数据的控件周围显示自定义验证错误模板。发生的是,当我扩展扩展器时,ContentPresenter内部的所有控件都被覆盖,但是我显示的红色边框和感叹号仍然可以通过扩展器看到!我已经验证了扩展器的ZIndex为99,ContentPresenter的ZIndex为0。有人可以帮我吗?



以下是一些图片来帮助说明:



第一张图片显示未展开时的视图外观。



第二张图片显示了

我定义验证错误模板是这样的:

 < ControlTemplate x:Key = ValidationErrorTemplate> 
< DockPanel LastChildFill = true>
< Border Background = Red DockPanel.Dock = right Margin = 5,0,0,0 Width = 10 Height = 10 CornerRadius = 5
工具提示= {Binding AdornedElement。(Validation.Errors).CurrentItem.ErrorContent,ElementName = customAdorner}>
< TextBlock Text =! VerticalAlignment = center Horizo​​ntalAlignment = center FontWeight = Bold Foreground = White />
< / Border>
< AdornedElementPlaceholder x:Name = customAdorner VerticalAlignment = Center>
< Border BorderBrush = red BorderThickness = 1 />
< / AdornedElementPlaceholder>
< / DockPanel>
< / ControlTemplate>

并将其分配给这样的特定控件(这是我为TextBox所做的操作):

 < Style TargetType = {x:Type TextBox} x:Key = ValidatedStyleTextBox> 
< Style.Triggers>
< DataTrigger Binding = {Binding IsLocked} Value = True>
< Setter Property = Validation.ErrorTemplate Value = {x:Null} />
< / DataTrigger>
< DataTrigger Binding = {Binding IsLocked} Value = False>
< Setter Property = Validation.ErrorTemplate Value = {StaticResource ValidationErrorTemplate} />
< / DataTrigger>
< /Style.Triggers>
< / Style>


解决方案

此解决方案对我有用...只是在与我的扩展器相同级别上添加了一个AdornerDecorator ,所以现在,AdornerDecorator内部的控件使用该层而不是窗口中的顶层来显示


I have a view defined as a DataTemplate (for an "OrderEntryViewModel") with a Menu, ContentPresenter, and Expander inside of a 3-row grid. The content of the ContentPresenter is binded to another viewModel "OrderViewModel" (for which there's another DataTemplate-defined view). The expander has a ZIndex of 99, so that when it expands UP, it expands OVER any other controls (i.e. the ContentPresenter).

This all works as expected EXCEPT when the ContentPresenter's content (the OrderViewModel) has data errors...My OrderView displays a custom validation error template around controls with invalid data. What happens is, when I expand the expander, all of controls inside the ContentPresenter are covered, but the red border and exclamation point I show are still visible through the expander! I've verified that my expander's ZIndex is 99 and the ContentPresenter's is 0. Can anyone help me with this?

Here's some images to help explain:

First Image shows what the views look like when NOT expanded.

Second Image shows what the views look like when I expand.

I define the validation error template like this:

<ControlTemplate x:Key="ValidationErrorTemplate">
    <DockPanel LastChildFill="true">
        <Border Background="Red" DockPanel.Dock="right" Margin="5,0,0,0" Width="10" Height="10" CornerRadius="5" 
                ToolTip="{Binding AdornedElement.(Validation.Errors).CurrentItem.ErrorContent, ElementName=customAdorner}">
            <TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" FontWeight="Bold" Foreground="White"/>
        </Border>
        <AdornedElementPlaceholder x:Name="customAdorner" VerticalAlignment="Center">
            <Border BorderBrush="red" BorderThickness="1" />
        </AdornedElementPlaceholder>
    </DockPanel>
</ControlTemplate>

And assign it to a specific control like this (this is how I do it for my TextBox):

<Style TargetType="{x:Type TextBox}" x:Key="ValidatedStyleTextBox">
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsLocked}" Value="True">
            <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding IsLocked}" Value="False">
            <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ValidationErrorTemplate}"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

解决方案

This solution worked for me...just added an AdornerDecorator at the same level as my expander, so now, the controls inside of the AdornerDecorator use that layer to display instead of the top level layer in the window

这篇关于自定义验证错误模板不符合ZIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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