2010-12-29 8 views
5

テキストボックスにエラーがある場合、文字列を返すためにIDataErrorInfoをViewModelに実装しました。WPF-検証 - AdornerDecoratorのために検証エラーメッセージが他のコントロールの背後に表示される

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

ただし、このエラーメッセージはUIの他のコントロールの後ろに表示されます(下の図を参照)。以下は

alt text

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> 

私は、エラーメッセージが他のコントロールを重複し、背後に行かないようにAdornerDecoratorを使用する方法を教えてください。

私のアプリケーションでは、AdornerDecoratorを使用しないと、エラーメッセージがまったく表示されません。

答えて

3

AdornerDecoratorにGrid.ZIndexを追加する

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

おかげで十分なはずです...それは動作します。.. –

関連する問題