在ComboBox上使用Style设置ErrorTemplate允许工具提示但不允许鼠标单击

时间:2015-01-13 08:46:39

标签: wpf mouseevent errortemplate

我使用telerik,但这不应该对这个问题有多大意义。我的应用程序是WPF(.Net 4.5)。

我有一种风格,我用于所有组合框,它有一个errortemplate。风格如下:

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

我的ErrorTemplate看起来像这样:

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

整个事情在全局ResourceDictionary中定义。

这段代码的作用是什么,它是一个&#34;禁止的标志&#34;在组合框顶部(Panel.ZIndex =&#34; 999&#34;),在下拉按钮之前(使用边距)。 Border和Rectangle的符号大致如下:Picture

组合框本身必须能够保存工具​​提示,在本地设置。所以错误消息不能显示在组合框的工具提示中 - 除非我找到一种方法将两者合并而不必在本地解析它(我想在我的resourcedictionary中使用该代码)。

我也不希望&#34;禁止标志&#34;处理鼠标点击(如果用户点击&#34;禁止的标志&#34,它会吞噬点击并防止组合框掉落。

我尝试在网格和ErrorTemplate内的边框上将IsHitTestVisible设置为false,但这导致Tooltip永远不会显示。 我也尝试在相同的两个控制器上将IsEnabled设置为false,但这不会将鼠标点击发送到组合框本身(组合框中的列表不会下降)。

有没有办法直接在组合框样式或errortemplate中执行此操作?我甚至不介意有代码 - 但我真的不想在使用组合框样式的地方添加代码。

0 个答案:

没有答案