绑定不适用于错误验证

时间:2014-07-21 12:17:49

标签: c# .net wpf wpf-controls

我有一个控件的验证错误的样式。我在工具提示中显示错误我也希望在控件旁边的Textblock中显示它。工具提示中的绑定工作正常但它不能与textblock一起使用。我试过硬编码一些文本在textblock中它可以工作,但绑定不起作用。

 <Style TargetType="{x:Type Control}" x:Key="S_ErrorTemplate">
    <Setter Property="Validation.ErrorTemplate">
        <Setter.Value>
            <ControlTemplate>
                <DockPanel LastChildFill="True">
                    <TextBlock DockPanel.Dock="Right" Foreground="Red" 
                      FontSize="12pt" 
                    Text="{Binding Path=(Validation.Errors)[0].ErrorContent,
                           RelativeSource={RelativeSource TemplatedParent}}" />
                    <Border BorderBrush="Green" BorderThickness="1" >
                        <AdornedElementPlaceholder Name="myControl"/>
                    </Border>
                </DockPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="true">
            <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},
            Path=(Validation.Errors)[0].ErrorContent}"/>
            <Setter Property="Background" Value="Maroon"/>
        </Trigger>
    </Style.Triggers>
</Style>

0 个答案:

没有答案