使用一个类库(和主题)作为另一类库的基础 [英] Using one class library (and theme) as basis to another class library
问题描述
仍然要学习有关WPF,主题,派生等的内容.
Still learning this stuff on WPF, themes, derivations, etc.
我了解"Themes \ Generic.xaml"的基础知识,然后将应用程序的app.xaml文件设置为包括指向相关主题的资源字典.
I understand basics on the "Themes\Generic.xaml", and then setting your application's app.xaml file to include the resource dictionary pointing to the theme in question.
因此,从应用程序项目的角度来看就可以了.现在,从类库/dll文件中查找.我有一个DLL项目,希望将其用作项目中所有控件的基础.这样,我就拥有了Themes/Generic.xaml,并用一些基础代码对其进行了编码,以确认视觉设计的实现(最初在应用程序/exe项目下进行测试时确定为可以).
So, thats fine from an application project perspective. Now, how about from a class library/dll file. I have a DLL project which I want to use as the basis of all controls in my project. In that, I have the Themes/Generic.xaml and have it coded up with some basics to confirm visual design implementation (originally confirmed ok, when tested under an App/exe project).
现在,我希望这个主题在实际应用之前达到一个水平.同样,这是基线.现在,我添加了第二个自定义分组控件库(例如,用于地址信息的用户控件...多个地址行,城市,州,邮政编码,标签等).我希望第二个库引用具有主题的第一个库,以便在设计时可以直观地看到它的外观(对齐方式,颜色,字体等).
Now, I want this theme at a level BEFORE the actual application. Again, this is the baseline. Now, I add a second library of custom grouped controls (for example, a user control for address information... multiple address lines, city, state, zip, labels, etc). I want this second library to reference the first library with the themes, so I can see visually at design time what it will look like (alignments, colors, fonts, etc).
我应该在哪里/什么地方让一个DLL知道作为第一个DLL基础的合并字典.希望这是有道理的.
What / where should I be looking to let one DLL know about the merge dictionaries that are the basis in the first DLL. Hope this makes sense.
-编辑-为澄清
第一类库..."MyThemeLibrary"编译为.dll 在这个dll中是"/Themes/MyTheme.xaml"的路径/文件
First Class Library... "MyThemeLibrary" compiles into a .dll In this dll is path/file of "/Themes/MyTheme.xaml"
根据第一个答案的建议,如果我在第一个库中有一个资源字典,则可以从它派生的任何其他内容中引用它.所以,我有
As suggested by first answer, if I have a Resource Dictionary in the first library, I can reference it in anything else that I will derive from it. So, I have
<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>
第二个类库..."SecondLevel"编译成一个.dll 在此,我有一个用户控件,希望将网格用于列/行,标签和文本框控件.我希望控件尊重第一个dll的"MyTheme.xaml"中定义的颜色,字体,大小和对齐方式.
Second Class Library... "SecondLevel" compiles into a .dll In this, I have a user control that I want to put a grid for columns/rows, labels and textbox controls into. I want the controls to respect the colors, fonts, sizes, alignments as defined in the "MyTheme.xaml" of the first dll.
<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>
所以,我应该/如何做从第一个库到第二个库的必要引用,声明和资源字典的包含.
So, how / what should I do the necessary reference, declaration, inclusion of resource dictionary from the first library into the second.
推荐答案
引用您的dll,如果您知道主题所在的位置,则可以执行此操作
make a reference to your dll and if you know where your theme is located you can do this one
<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中执行此操作
do this in the App.xaml
EDIT (查看评论)
<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>
这篇关于使用一个类库(和主题)作为另一类库的基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!