首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于AdornerDecorator的原因,WPF- Validation -The验证错误消息滞后于其他控件

由于AdornerDecorator的原因,WPF- Validation -The验证错误消息滞后于其他控件
EN

Stack Overflow用户
提问于 2010-12-29 15:37:09
回答 1查看 1.6K关注 0票数 5

我在ViewModel中实现了IDataErrorInfo,以便在文本框有错误时返回一个字符串。

代码语言:javascript
复制
    public string this[string columnName]
    {
        get { return "Error-- This is a long error message - sd"; }
    }

但此错误消息位于UI上的其他控件后面,如下所示。

下面是xaml:

代码语言:javascript
复制
<Window x:Class="Test.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="600" Width="600">

<Window.Resources>        
    
    <ControlTemplate x:Key="validationTemplateNew">
        <DockPanel LastChildFill="True">
            <TextBlock Name="ErrorText" DockPanel.Dock="Bottom" Foreground="White" Background="Red" 
                                   FontSize="12" Padding="2" FontFamily="Trebuchet MS" 
                                   Margin="5,5,0,0"                                        
                                   TextWrapping="Wrap"                                        
                                   Text="{Binding [0].ErrorContent}" ></TextBlock>
            <AdornedElementPlaceholder Name="ErrorTextBox" />
        </DockPanel>
    </ControlTemplate>
    <Style x:Key="ValidationStyle" TargetType="{x:Type TextBox}">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="True">
                <Setter Property="BorderBrush" Value="Red" />
                <Setter Property="BitmapEffect">
                    <Setter.Value>
                        <BitmapEffectGroup>
                            <OuterGlowBitmapEffect GlowColor="Red" GlowSize="3" Noise="0.6"></OuterGlowBitmapEffect>
                        </BitmapEffectGroup>
                    </Setter.Value>
                </Setter>                    
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

<Grid>
    <ItemsControl Name="ItemCtrl">

        <AdornerDecorator>
            <TextBox 
             FontSize="11" 
             Margin="10" 
             Width="250"      
             VerticalAlignment="Center"                                         
             Text="{Binding Path=StrText, ValidatesOnDataErrors=True, 
                    UpdateSourceTrigger=PropertyChanged}" 
             Validation.ErrorTemplate="{StaticResource validationTemplateNew}"
            Style="{StaticResource ValidationStyle}"
             
             >
            </TextBox>
        </AdornerDecorator>
        <TextBox Width="250" Text="ASDFASFASDFASDFASDFASDFASDF"/>
        <TextBox Width="250" Text="ASDFASFASDFASDFASDFASDFASDF"/>
        <TextBox Width="250" Text="ASDFASFASDFASDFASDFASDFASDF"/>
        <TextBox Width="250" Text="ASDFASFASDFASDFASDFASDFASDF"/>
        <TextBox Width="250" Text="ASDFASFASDFASDFASDFASDFASDF"/>
    </ItemsControl>        
</Grid>

</Window>

请让我知道如何使用AdornerDecorator,以便错误消息与其他控件重叠,而不会落后。

我的应用程序是这样的:如果我不使用AdornerDecorator,则根本不会显示错误消息。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-12-29 18:25:58

在AdornerDecorator上添加Grid.ZIndex应该就足够了

代码语言:javascript
复制
<Grid>
    <ItemsControl Name="ItemCtrl">
        <AdornerDecorator Grid.ZIndex="1">
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4552313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档