Make ErrorTemplate in Style on ComboBox allow tooltip but not mouse click

170 Views Asked by At

I use telerik, but that should not mean much for this question. My application is WPF (.Net 4.5).

I have a style, that I use for all comboboxes, which has an errortemplate. The style looks like this:

  <Style TargetType="{x:Type telerik:RadComboBox}" x:Key="RadComboBoxStyle" >
            <Setter Property="FontFamily" Value="Calibri"/>
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="Background" Value="{StaticResource InputBrush}" />
            <Setter Property="BorderBrush" Value="{StaticResource InputBorderBrush}" />
            <Setter Property="Validation.ErrorTemplate" Value="{StaticResource RadComboBoxValidationErrorTemplate}" />
        </Style>

My ErrorTemplate looks like this:

<ControlTemplate TargetType="{x:Type Control}" x:Key="RadComboBoxValidationErrorTemplate">

            <Grid ToolTipService.IsEnabled="True" ToolTipService.ShowOnDisabled="True" 
                        ToolTip="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors), Converter={StaticResource ValidationErrorsConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Border BorderBrush="{StaticResource ErrorBrush}" BorderThickness="3" Panel.ZIndex="999" HorizontalAlignment="Right" Margin="0,0,10,0"
                        Background="Transparent" DockPanel.Dock="right"  Width="16" Height="16" CornerRadius="10">
                    <Rectangle Fill="{StaticResource ErrorBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="3" RenderTransformOrigin="0.5,0.5">
                        <Rectangle.RenderTransform>
                            <RotateTransform Angle="315" />
                        </Rectangle.RenderTransform>
                    </Rectangle>
                </Border>

                <AdornedElementPlaceholder Name="customAdorner" VerticalAlignment="Center" >
                    <Border BorderBrush="{StaticResource ErrorBrush}" BorderThickness="1"  />
                </AdornedElementPlaceholder>

            </Grid>

        </ControlTemplate>

The entire thing is defined in a global ResourceDictionary.

What this code does, it to put a "forbidden sign" on top of the combobox (Panel.ZIndex="999"), just before the dropdown button (using margins). The Border and the Rectangle makes a sign much like this: Picture.

The combobox itself must be able to hold a tooltip, set locally. So the error-message cannot be shown in the tooltip of the combobox - unless I find a way to combine the two without having to resolve it locally (I want that code in my resourcedictionary).

I also do not want the "forbidden sign" to handle mouse clicks (it gobbles up the click and prevent the combobox from dropping down, if the user clicks on the "forbidden sign".

I tried setting IsHitTestVisible to false on the grid and on the border inside the ErrorTemplate, but that caused the Tooltip to never show. I also tried setting IsEnabled to false on the same two constrols, but that would not send the mouseclick on to the combobox itself (the list in the combobox does not drop down).

Is there any way to do this directly in the combobox-style or errortemplate? I do not even mind having a code behind - but I really do not want to add code locally where the combobox-style is used.

0

There are 0 best solutions below