WPF拇指。无法摆脱焦点风格

时间:2011-07-08 06:09:40

标签: wpf .net-3.5

这是我创建的拇指风格......(三角形)。 虽然我摆脱了鼠标悬停等风格,但无论我做什么,我都无法摆脱焦点......

我创建了一个多边形以创建三角形... 我在滑块控件中使用那个拇指

  <Style x:Key="HorizontalSliderThumbStyle" TargetType="{x:Type Thumb}">
                <Setter Property="Focusable" Value="false"/>
                <Setter Property="OverridesDefaultStyle" Value="true"/>
                <Setter Property="Height" Value="22"/>
                <Setter Property="Width" Value="11"/>
                <Setter Property="Foreground" Value="Gray"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Thumb}">
                            <Canvas SnapsToDevicePixels="true">
                                <Canvas.RenderTransform>
                                    <TranslateTransform X="5.5" Y="11"/>
                                </Canvas.RenderTransform>                           
                                <Path x:Name="InnerBorder" Stroke="White"/>
                                <Path x:Name="OuterBorder" Stroke="#FF929292"/>
                                <Polygon  FocusVisualStyle="{x:Null}"  x:Name="Background"   Points="0,0 1,0 0.5,1"    Fill="#FFF18200"  Width="15.3"  Height="15"  Stretch="Fill"   Canvas.Left="-7.5" Canvas.Top="-8" RenderTransformOrigin="0.5,0.5" />
                            </Canvas>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="true">
                                <!--    <Setter Property="Fill" TargetName="Background" Value="{StaticResource HorizontalSliderThumbHoverBackground}"/>
                                    <Setter Property="Stroke" TargetName="OuterBorder" Value="{StaticResource HorizontalSliderThumbHoverBorder}"/>-->
                                </Trigger>
                                <Trigger Property="Foreground" Value="Blue">
                                    <Setter Property="Fill" TargetName="Background" Value="{StaticResource HorizontalSliderThumbHoverBackground}"/>
                                    <Setter Property="Stroke" TargetName="OuterBorder" Value="{StaticResource HorizontalSliderThumbHoverBorder}"/>
                                </Trigger>
                                <Trigger Property="IsDragging" Value="true">
                                <!--    <Setter Property="Fill" TargetName="Background" Value="{StaticResource HorizontalSliderThumbPressedBackground}"/>
                                    <Setter Property="Stroke" TargetName="OuterBorder" Value="{StaticResource HorizontalSliderThumbPressedBorder}"/>-->
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter Property="Fill" TargetName="Background" Value="#FFF4F4F4"/>
                                    <Setter Property="Stroke" TargetName="InnerBorder" Value="{x:Null}"/>
                                    <Setter Property="Data" TargetName="OuterBorder" Value="{StaticResource SliderThumbDisabledGeometry}"/>
                                    <Setter Property="Stroke" TargetName="OuterBorder" Value="#FFAEB1AF"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

2 个答案:

答案 0 :(得分:0)

 <Trigger Property="Foreground" Value="Blue">
                                    <Setter Property="Fill" TargetName="Background" Value="{StaticResource HorizontalSliderThumbHoverBackground}"/>
                                    <Setter Property="Stroke" TargetName="OuterBorder" Value="{StaticResource HorizontalSliderThumbHoverBorder}"/>


         </Trigger>

哦,上帝这个属性做了问题..我觉得这真的很奇怪。蓝色对我没什么意义......不知道为什么微软这样做了..

答案 1 :(得分:0)

将Thumb Style上的FocusVisualStyle设置为null。