如何像在应用程序项目设计器中一样隐式地在组件设计器中应用主题?
假设我有一个标准按钮的主题文件 Button.xaml。
通过合并到应用程序资源字典中,它可以隐式应用于应用程序项目设计器中。
但是当我将 Button.xaml 移动到组件项目后,组件项目设计器无法隐式应用主题文件。
如何使该主题文件在组件项目中隐式工作?
更新: Themes.xaml 如下
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/StyleLibrary;component/Themes/Shared.xaml" />
<ResourceDictionary Source="pack://application:,,,/StyleLibrary;component/Themes/Button.xaml" />
<ResourceDictionary Source="pack://application:,,,/StyleLibrary;component/Themes/ComboBox.xaml" />
...
<Application x:Class="ButtonStyleTest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/StyleLibrary;component/Themes.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
如果我使用合并的 Theme.xaml,按钮在设计器中看起来正常,但在运行时失败。 但如果我将 Button.xaml、ComboBox 一一合并,无论是设计还是运行时,它看起来都很正常。
Say i had a theme file Button.xaml for standard button.
By merged in application resource dictionary it can implicitly applied in application project designer.
But after i move Button.xaml to component project, the component project designer can not implicitly apply the theme file.
How can i make that theme file works implicitly in component project ?
Update:
the Themes.xaml as follow
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/StyleLibrary;component/Themes/Shared.xaml" />
<ResourceDictionary Source="pack://application:,,,/StyleLibrary;component/Themes/Button.xaml" />
<ResourceDictionary Source="pack://application:,,,/StyleLibrary;component/Themes/ComboBox.xaml" />
...
<Application x:Class="ButtonStyleTest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/StyleLibrary;component/Themes.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
If i use merged Theme.xaml, the Button look normal in designer, but failed in runtime.
But if i merge Button.xaml, ComboBox one by one, it look normal for both design and runtime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
新的例子。
假设您有一个名为 StyleLibrary 的库。
在此库中,您有一个名为 Button.xaml 的 ResourceDictionary,如下所示
在应用程序中,我们添加对 StyleLibrary 的引用,并在 App.xaml 中添加它。
此样式将在运行时和设计器中应用于应用程序和库中。
左边是我的主窗口。它有一个自己的按钮,然后是 TestLibrary 中的一个具有两个按钮的用户控件。右侧是 TestLibrary 中的一个窗口,其中包含 TestLibrary 中的一个 UserControl,所有按钮似乎都应用了该样式。
New example.
Say that you have a Library called StyleLibrary.
In this Library you have a ResourceDictionary called Button.xaml which looks like this
In the Application we then add a reference to StyleLibrary and in App.xaml we add this.
This style will apply in the Application and in the Libraries both in runtime and in designer.
To the left is my MainWindow. Is has one Button of its own, and then a UserControl from TestLibrary that has two Buttons. To the right is a Window from TestLibrary which contains one UserControl from TestLibrary, all Buttons seem to have the style applied.