0

私はアップダウンコントロールに取り組んでいて、それはうまく機能していますが、今日、コントロールの繰り返しボタンに奇妙な問題があることに気づきました。+/-リピートボタンをクリックすると、青い境界線で強調表示されますが(問題ありません)、問題は、ページ上の他のボタンやコントロールをクリックしても強調表示されたままになることです。

これがスクリーンショットです-

ここに画像の説明を入力してください

これが私が使用している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

このセッターを交換する必要があると思います。

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

このようにして、トリガー条件がfalse(この場合はマウスが外れている)のときにストロークをデフォルト値に戻します。

于 2011-11-23T16:24:48.547 に答える
0

この問題を解決するために私が見つけた唯一の解決策はFocusable="False"、RepeatButtonを設定することです。

于 2011-11-25T06:23:29.857 に答える