2011-11-15 27 views
0

仍在學習WPF的這個東西,主題,推導等等使用一個類庫(和主題)爲基礎,另一個類庫

我理解的「主題\ Generic.xaml」基礎知識,然後設置您的應用程序的app.xaml文件包含指向相關主題的資源字典。

所以,從應用程序項目的角度來看,這很好。現在,從類庫/ dll文件怎麼樣。我有一個DLL項目,我想用它作爲我項目中所有控件的基礎。在那裏,我有主題/ Generic.xaml,並有一些基礎知識來確認視覺設計實現(最初確認好,當在App/exe項目下測試時)。

現在,我希望這個主題在實際應用程序之前的級別。再次,這是基準線。現在,我添加了第二個自定義分組控件庫(例如,地址信息的用戶控件......多個地址行,城市,州,郵編,標籤等)。我希望這第二個庫引用第一個庫的主題,所以我可以在設計時看到它的外觀(對齊,顏色,字體等)。

什麼/我應該在哪裏讓一個DLL知道第一個DLL中基礎的合併字典。希望這是有道理的。

- 編輯 - 澄清

首先類庫...... 「MyThemeLibrary」 編譯成一個.dll 在此DLL的 「/Themes/MyTheme.xaml」

路徑/文件

正如第一個答案所建議的,如果我在第一個庫中有一個資源字典,我可以參考它來引用它。所以,我有

<ResourceDictionary x:Name="MyGenericTheme" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <ResourceDictionary.MergedDictionaries> 
     <ResourceDictionary Source="/Themes/MyTheme.xaml"/> 
    </ResourceDictionary.MergedDictionaries> 
</ResourceDictionary> 

二類庫......「第二級別」編譯成一個.dll 在這方面,我有我想提出列/行,標籤和文本框控件網格用戶控制成。我希望控件尊重第一個dll的「MyTheme.xaml」中定義的顏色,字體,大小和路線。

<UserControl x:Class="SecondLevel.multipleControlContainer" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > 

    <Grid> 
     <Grid.ColumnDefinitions> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
     <RowDefinition /> 
     </Grid.RowDefinitions> 

     <Label Content="Something" 
     Grid.Row="0" Grid.Column="0" /> 

     <TextBox Text="Testing" Grid.Row="1" Grid.Column="1" /> 
    </Grid> 
</UserControl> 

那麼,究竟應該如何/我做了必要的參考,聲明,包括資源字典從第一庫到第二位。

回答

1

作個參考,以您的DLL,如果你知道你的主題所在,你可以這樣做一個

<Application x:Class="My.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
     <!-- Common base theme --> 
     <ResourceDictionary Source="pack://application:,,,/Your.Base.Dll;component/YourResDictionary/YourTheme.xaml" /> 

     <!-- here comes your custom theme --> 

     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
    </Application.Resources> 
</Application> 

做到這一點在App.xaml中

編輯澄清後(看評論)

<UserControl x:Class="SecondLevel.multipleControlContainer" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 

    <UserControl.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
     <!-- Common base theme --> 
     <ResourceDictionary Source="pack://application:,,,/Your.Base.Dll;component/YourResDictionaryFolder/MyGenericTheme.xaml" /> 
     <!-- Custom theme --> 
     <ResourceDictionary Source="pack://application:,,,/Another.Dll;component/AnotherResDictionaryFolder/MyCustomTheme.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
    </UserControl.Resources> 

    <Grid> 
    <!-- all controls in this usercontrol respect the styles in MyGenericTheme.xaml" 
     if you use implicite styles--> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
    </Grid.RowDefinitions> 
    <Label Content="Something" 
      Grid.Row="0" 
      Grid.Column="0" /> 
    <TextBox Text="Testing" 
      Grid.Row="1" 
      Grid.Column="1" /> 

    <!-- if you use explicit styles then you must do this --> 

    <TextBox Style="{StaticResource myTextBoxStyle}" 
      Text="Testing" 
      Grid.Row="1" 
      Grid.Column="1" /> 
    </Grid> 
</UserControl> 
+0

我想你沒有得到它,並認爲我很清楚......我有我的主題在一個dll中,並希望第二級dll在設計時參考它ti我。不在最終的應用程序中(尚未)。第二個DLL不知道最終的應用程序。這就是爲什麼我試圖在DLL中獲得可見性。如果我不正確,你是否指出我可以將一個App.xaml添加到一個DLL文件中,並且它將以與最終應用程序相同的方式工作? – DRapp

+0

嗨,如果在你的第一個DLL中存在一個資源字典,你可以在你的第二個DLL在資源中引用此字典 – punker76

+0

已更新的問題,更多細節... – DRapp