2013-03-08 75 views
1

我有一個按鈕樣式模板+如下:與自定義模板WPF按鈕只能被壓在內容

<Style x:Key="ButtonStyle" TargetType="RepeatButton"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="RepeatButton"> 
       <Border Background="{DynamicResource {x:Static SystemColors.ControlColor}}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">    
        <Path Data="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"> 
         <Path.Fill> 
          <SolidColorBrush x:Name="PathBrush" Color="{x:Static SystemColors.ControlDarkColor}" /> 
         </Path.Fill> 
        </Path> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

按鈕用於這樣的:

<RepeatButton Style="{StaticResource ButtonStyle}" Content="M 0 4 L 8 4 L 4 0 Z" /> 

然而,按鈕只能在鼠標移過路徑時按下,而不能在整個按鈕上按下。當鼠標在按鈕上但不在路徑上時,如何獲取按鈕?

回答

1

這是因爲您的ControlTemplate中的Border元素的Background屬性設置不正確。它期望Brush和你提供Color。由於它是DynamicResource,刷子根本沒有設置。所以點擊不可見。只需提供畫筆。

這應該做的伎倆:)

<Border Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">