2010-01-26 49 views

回答

19

您可以創建有問題的部分UI你自己的容器,並設置InheritanceBehaviorSkipAllNow(或您的具體情況的值):

using System.Windows; 
using System.Windows.Controls; 

public class NoInheritanceContentControl : ContentControl 
{ 
    public NoInheritanceContentControl() 
    { 
     InheritanceBehavior = InheritanceBehavior.SkipAllNow; 
    } 
} 

然後,你可以堅持NoInheritanceContentControl在你的可視樹和其中的任何東西都不會繼承樣式。

+0

聽起來很有希望。已經很晚了,但明天我會試試。 – 2010-01-26 08:31:21

+0

我等不及了。那正是我想要的。 – 2010-01-26 08:54:39

+0

謝謝謝謝謝謝你 – stone 2012-09-12 19:01:15

2

這是棘手的,但你可以試試這個,

  1. 創建DefaultStyles資源字典
  2. 創建命名樣式要保留的如下默認樣式控制的..
<Style x:Key="DefaultButtonStyle" 

TargetType =「{x:Type Button}」BasedOn =「{StaticResource {x:Type Button}}」/>

  1. 確保在應用任何主題前添加了這個DefaultStyles,它應該是您的應用程序資源中的第一個條目。

  2. 然後,您可以在運行時對任何控件應用樣式「DefaultButtonStyle」以保留其默認樣式。