0

我正在研究我的 Up Down 控件,它工作正常,但今天我注意到控制中的重复按钮存在一个奇怪的问题。一旦我单击 +/- 重复按钮,它们就会以蓝色边框突出显示(很好),但问题是即使我单击页面上的其他按钮或控件,它们仍然突出显示。

这是屏幕截图 -

在此处输入图像描述

这是我正在使用的 xaml -

<!--  RepeatButton styles  -->

<Style
    x:Key="RepeatButtonPathStyle"
    TargetType="Path">
    <Setter
        Property="Width"
        Value="3" />
    <Setter
        Property="Height"
        Value="3" />
    <Setter
        Property="MinWidth"
        Value="3" />
    <Setter
        Property="MinHeight"
        Value="3" />
    <Setter
        Property="HorizontalAlignment"
        Value="Center" />
    <Setter
        Property="VerticalAlignment"
        Value="Center" />
    <Setter
        Property="Stretch"
        Value="None" />
    <Setter
        Property="StrokeThickness"
        Value="1" />
    <Setter
        Property="Stroke"
        Value="{Binding RelativeSource={RelativeSource AncestorType=RepeatButton},
Path=Foreground}" />
</Style>

<DataTemplate
    x:Key="IncreaseGlyph">
    <Path
        Data="M0,1.5 H3 M1.5,0 V3"
        Style="{StaticResource RepeatButtonPathStyle}" />
</DataTemplate>

<DataTemplate
    x:Key="DecreaseGlyph">
    <Path
        Data="M0,1.5 H3"
        Style="{StaticResource RepeatButtonPathStyle}" />
</DataTemplate>

<Grid
    Grid.Column="1">
    <Grid.RowDefinitions>
        <RowDefinition
            Height="*" />
        <RowDefinition
            Height="*" />
    </Grid.RowDefinitions>
    <Button
        Grid.Row="0"
        Grid.RowSpan="2"
        IsHitTestVisible="True"
        IsTabStop="False">
        <Button.Template>
            <ControlTemplate
                TargetType="Button">
                <Grid
                    Background="Transparent" />
            </ControlTemplate>
        </Button.Template>
    </Button>
    <RepeatButton
        Grid.Row="0"
        HorizontalContentAlignment="Center"
        Command="{Binding RelativeSource={RelativeSource TemplatedParent}, 
            Path=IncreaseCommand}"
        ContentTemplate="{StaticResource IncreaseGlyph}"
        ToolTip="{Binding RelativeSource={RelativeSource TemplatedParent}, 
            Path=IncreaseButtonToolTip}"
        ToolTipService.BetweenShowDelay="1000"
        ToolTipService.InitialShowDelay="1000"
        ToolTipService.IsEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, 
            Path=ShowUpDownButtonToolTip}">
    </RepeatButton>
    <RepeatButton
        Grid.Row="1"
        HorizontalContentAlignment="Center"
        Command="{Binding RelativeSource={RelativeSource TemplatedParent}, 
            Path=DecreaseCommand}"
        ContentTemplate="{StaticResource DecreaseGlyph}"
        ToolTip="{Binding RelativeSource={RelativeSource TemplatedParent}, 
            Path=DecreaseButtonToolTip}"
        ToolTipService.BetweenShowDelay="1000"
        ToolTipService.InitialShowDelay="1000"
        ToolTipService.IsEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, 
            Path=ShowUpDownButtonToolTip}">
    </RepeatButton>
</Grid>

任何指针?

4

2 回答 2

0

我发现解决此问题的唯一解决方案是设置Focusable="False"重复按钮。

于 2011-11-25T06:23:29.857 回答
0

我认为你应该更换这个二传手:

<Setter Property="Stroke" Value="{Binding RelativeSource=
{RelativeSource AncestorType=RepeatButton},Path=Foreground}" />

用触发器代替:

<Style.Triggers>
  <Trigger Property="IsMouseOver" Value="true">
    <Setter Property="Stroke" 
            Value="{Binding RelativeSource={RelativeSource AncestorType=RepeatButton},
                      Path=Foreground}" />
  </Trigger>
</Style.Triggers>

这样,当您的触发条件为假(在这种情况下,鼠标不在)时,它会将笔画设置回其默认值。

于 2011-11-23T16:24:48.547 回答