2012-10-01 115 views
0

這是我的C#代碼全局樣式不適用

MainWindow.Content = new UserControl(); 

主窗口導航到一個新的用戶控件後,全局樣式 在App.xaml中

<Application.Resources> 
    <Style TargetType="{x:Type UserControl}"> 
     <Setter Property="Background" Value="Red" /> 
    </Style> 
</Application.Resources> 

定義它 並不適用,但在Visual Studio中,構造函數顯示UserControl通過更改背景來應用該樣式 我應該怎麼做?

回答

0

您確定在UserControl本身沒有設置背景值? 要查找像UserControl.Background的Dependency屬性的實際值WPF使用設置的順序。如果直接設置Background屬性,則樣式不會覆蓋它(請參閱Dependency Property Value Precedence)。