2011-11-23 78 views
0

我可以在我的Up Down控制工作,它工作正常,但今天我注意到一个奇怪的问题与控制中的重复按钮。一旦我点击+/-重复按钮,他们会突出显示蓝色边框(这很好),但问题是,即使我点击页面上的其他按钮或控件,它们仍然保持突出显示。RepeatButtons没有失去焦点,并保持永远高亮

下面是截图 -

enter image description here

,这里是我使用的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> 

任何指针?

回答

0

我发现解决此问题的唯一解决方案是在RepeatButton上设置Focusable="False"

0

我想你应该更换此setter:

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

这样,它会行程设置恢复到默认值时,您的触发条件为假(在这种情况下鼠标熄灭)。

+0

感谢chaosmaker,但是这并不能解决问题;笔画仅用于设置+/-按钮的颜色,我觉得它与焦点问题没有关系。 – akjoshi