2010-12-29 28 views
5

Tôi đã triển khai IDataErrorInfo trong ViewModel của mình để trả về một chuỗi nếu hộp văn bản có lỗi.WPF- Xác thực -Thông báo lỗi xác thực đi sau các điều khiển khác vì AdornerDecorator

public string this[string columnName] 
    { 
     get { return "Error-- This is a long error message - sd"; } 
    } 

Nhưng thông báo lỗi này nằm sau điều khiển khác trên giao diện người dùng như được hiển thị bên dưới.

alt text

Dưới đây là XAML:

<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> 

Xin vui lòng cho tôi biết làm thế nào để sử dụng AdornerDecorator như vậy mà thông báo lỗi trùng lặp các điều khiển khác và không đi đằng sau.

Đơn đăng ký của tôi là như vậy nếu tôi không sử dụng AdornerDecorator, thông báo lỗi sẽ không hiển thị.

Trả lời

3

Thêm Grid.ZIndex trên AdornerDecorator nên đủ

<Grid> 
    <ItemsControl Name="ItemCtrl"> 
     <AdornerDecorator Grid.ZIndex="1"> 
+0

Cảm ơn .. Nó hoạt động .. –

Các vấn đề liên quan