2012-03-09 88 views
0

我需要刪除所選狀態(效果)或從我的界面中的每個控件調用的任何內容。你知道黑色的虛線...刪除所有模板的狀態(全局樣式)

它有什麼辦法呢?

P.S.完全自定義的XAML頁面使用30MB RAM是否正常?

在此先感謝。

+2

Your P.S.應作爲單獨的問題發佈。 – CodeNaked 2012-03-09 14:01:18

回答

0

這是相關控制的FocusVisualStyle的控制。不幸的是,您無法使用單個Style或設置全局禁用所有控件。相反,你必須單獨關閉每種控制類型。

例如,您可以在您的Application.Resources以下樣式將其關閉指定的控件:

<Style TargetType="Button"> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}" /> 
</Style> 
<Style TargetType="RepeatButton"> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}" /> 
</Style> 
<Style TargetType="ToggleButton"> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}" /> 
</Style> 
<Style TargetType="TreeViewItem"> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}" /> 
</Style> 
<!-- ETC --> 

但請記住,如果你使用Style財產上的任何控件或如果您有任何其他隱式樣式被定義,那麼這些會阻止上面的樣式被應用。

或者像瑞秋指出,你可以這樣做:

<Style x:Key="FrameworkElementStyleKey" TargetType="FrameworkElement"> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}" /> 
</Style> 
<Style TargetType="Button" BasedOn="{StaticResource FrameworkElementStyleKey}" /> 
<Style TargetType="RepeatButton" BasedOn="{StaticResource FrameworkElementStyleKey}" /> 
<Style TargetType="ToggleButton" BasedOn="{StaticResource FrameworkElementStyleKey}" /> 
<Style TargetType="TreeViewItem" BasedOn="{StaticResource FrameworkElementStyleKey}" /> 
<!-- ETC --> 

在功能上,這兩種方法上面有同樣的效果。

+1

您可以進一步簡化樣式,方法是爲'FrameworkElement'創建一個基礎樣式,其中包含'FocusVisualStyle',然後使用從基礎樣式繼承的單行控件樣式。有一個很好的例子[這裏](http://stackoverflow.com/a/7604656/302677) – Rachel 2012-03-09 14:27:43