Hi folks,
since nobody answered, I'll try to rephrase what I'd like to do:
I'm changing the appearance of (databound) controls that contain a validation error - a red border around them is added and a textblock to their right that contains a white exclamation mark on a red background. Th "!"-textblock's tooltip is then containing the error message.
I'd now like to change the appearance of the validation error tooltip, without influencing the way "regular" tooltips are being displayed. What I tried to do is to change the Tooltip being displayed in my ErrorValidation template directly, like:
<Style x:Key="ErrorValidationTooltip" TargetType="{x:Type ToolTip}">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="White"/>
</Style>
<Style x:Key="ErrorTemplate" TargetType="Control">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel LastChildFill="True" Margin="3">
<TextBlock DockPanel.Dock="Right" Foreground="White" FontSize="14" FontWeight="Bold" Background="Red" Padding="3">
<TextBlock.Text>!</TextBlock.Text>
<TextBlock.ToolTip>
<ToolTip Style="{StaticResource ErrorValidationTooltip}" >
<TextBlock Text="{Binding Path=AdornedElement.ToolTip, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Adorner}}}"/>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
<Border BorderBrush="Red" BorderThickness="1">
<AdornedElementPlaceholder Name="Control_AdornedElementPlaceholder"/>
</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}" />
</Trigger>
</Style.Triggers>
</Style>
But with the above XAML, the inner Textblock cannot find the error message:
Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Documents.Adorner', AncestorLevel='1''. BindingExpression:Path=AdornedElement.ToolTip; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
So it seems that all I really need is to change the binding of the TextBlock contained in the tooltip (unless there's a better way of doing this).
Any ideas?
Cheers,
Olaf