WPF中Style文件引用另一個Style文件中的樣式


第1種方法:

     直接在當前Style文件(*.xaml)文件中使用:

     <ResourceDictionary.MergedDictionaries>來進行合並

 
        
1 <!--
2     關鍵是注意source屬性,使用的是相對路徑
3     1.如果引入的Style文件與當前文件在同一個目錄,直接寫文件名 abc.xaml即可
4    2.其他的使用當前項目的相對路徑
5 -->
6 <ResourceDictionary.MergedDictionaries> 
7         <ResourceDictionary Source="Dictionaries/Buttons.xaml" />
8     </ResourceDictionary.MergedDictionaries> 
View Code

 

第2種方法:

     也是對Style文件進行合並,不過將作用范圍加大了,在Application的級別來進行合並,

     在App.xaml中使用 <ResourceDictionary.MergedDictionaries>來進行合並,如:    

 1 <Application x:Class="DriverEasyWPF.App"
 2              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4              StartupUri="MainWindow.xaml">
 5     <Application.Resources>
 6         <ResourceDictionary>
 7             <ResourceDictionary.MergedDictionaries>
 8                 
 9                 <ResourceDictionary Source="Style\windows.xaml"/>
10                 <ResourceDictionary Source="Style\tab.xaml"/>
11                 <ResourceDictionary Source="Style\tabitem.xaml"/>
12                 <ResourceDictionary Source="Style\Button.xaml" />
13             </ResourceDictionary.MergedDictionaries>
14         </ResourceDictionary>
15     </Application.Resources>
16 </Application>
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM