2010-01-07 103 views
3
<Window.Resources> 
<Style TargetType="{x:Type Button}">  
    <Setter Property="FontFamily" Value="Times New Roman" /> 
    <Setter Property="FontSize" Value="30" />  
    <Setter Property="FontWeight" Value="Bold" />  
    <Setter Property="Background" Value="#FFCA5132" /> 
</Style> 
</Window.Resources> 

此上面的代碼看起來像是將WPF樣式應用於特定窗口中的所有按鈕的正確選擇。但我想將這種風格應用於我的程序中的所有按鈕。 我想我需要在<Application.Resources></Application.Resources>中寫下這段代碼。但它不運行。我怎樣才能做到這一點?如何將WPF樣式應用於特定類型的所有元素?

+2

當你寫這Application.Resources會發生什麼。你有編譯器錯誤嗎?如果是這樣,你能告訴我們錯誤是什麼。 – Tarydon 2010-01-07 02:11:21

+0

那裏,格式化你的代碼。爲了將來的參考,在每行或每行代碼前放置四個空格,並且對於內嵌代碼''this''用反引號(''asdasd'')包圍它。現在,對於這個問題,當你把它放在Application.Resources中會發生什麼? – 2010-01-07 02:11:39

回答

0

<Application.Resources>ResourceDictionary。您無法將其添加到ResourceDictionaryStyle之間,就像您在代碼中所做的那樣。放置StyleResourceDictionary裏面,像這樣:

<Application.Resources>  

<ResourceDictionary Source="/PresentationFramework.Aero 
         , Version=3.0.0.0,Culture=neutral 
         , PublicKeyToken=31bf3856ad364e35 
         , ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml">    
    <ResourceDictionary.MergedDictionaries> 
    <ResourceDictionary Source="Style\AppStyle.xaml"></ResourceDictionary> 
    </ResourceDictionary.MergedDictionaries> 

    <Style TargetType="{x:Type Button}"> 
     <Setter Property="FontFamily" Value="meiryo" /> 
     <Setter Property="FontSize" Value="12" /> 
    </Style> 
    </ResourceDictionary> 
</Application.Resources> 
+0

感謝您的諮詢。但它仍然無法運行。 順便說一句,我有另一種解決方案。 在AppStyle.xaml文件中,我爲窗體窗體創建了一個樣式,並將按鈕樣式放在那裏。它運行正常! – huynq9 2010-01-07 04:23:21

相關問題