2010-03-05 64 views

回答

3

你將需要調整Button模板來做到這一點。首先獲取現有模板(在Blend中使用Edit Copy of Template),如果您只有Visual Studio,可以從文檔中獲得該模板。 Button Styles and Templates

複製整個風格和地方放置在一個資源在你的用戶控件或更好,但在它自己的資源字典文件,包含在用戶控件資源利用MergedDictionaries: -

NoFocusRectangleButtonStyle.xaml: -

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Style x:Key="NoFocusRectangleButtonStyle" TargetType="Button"> 
     <!-- copy of style contents from documentation --> 
    </Style> 
</ResourceDictionary> 

在你的用戶控件: -

<UserControl .... > 
    <UserControl.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="NoFocusRectangleButtonStyle.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
     <!-- other local resources --> 
    </ResourceDictionary> 
    </UserControl.Resources> 
    <Grid x:Name="LayoutRoot" ...> 

    <Button Style="{StaticResource NoFocusRectangleButtonStyle}"> 
     <Image Source="yourimage.png" /> 
    </Button> 

    </Grid> 
</UserControl> 

現在你只需要調整Template在複製樣式中刪除焦點Rectangle。 您會在模板的底部找到它,並將其刪除。然後再看看VisualStateGroups這一套的結尾,你會看到一個名爲「Focus」的VisualState,刪除它包含的Storyboard,你就完成了。

+0

很好的解決方案,謝謝。 – 2010-03-12 08:18:34

相關問題