如何在ClassLibrary项目的wpf窗口上应用样式? [英] How to apply style on wpf window on ClassLibrary project?

查看:140
本文介绍了如何在ClassLibrary项目的wpf窗口上应用样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我面临在类库项目(项目A)窗口中应用样式的问题,该窗口引用了另一个类库程序集(项目B)的样式.

这个问题有点琐碎.在项目A窗口中,我像往常一样使用ResourceDictionary.MergedDictionaries在xaml中应用了引用(就像在开发exe项目时在app.xaml中一样).

如果我把例如.按钮,并参考我的按钮样式Style ="{StaticResource myButtonStyle}"即可!从exe项目调用该窗口时,样式将在该按钮上的设计时间和过程中应用.这将应用该窗口内的所有组件.

如果我设置窗口自身样式问题,则会收到问题:资源无法解决"!?

引用的样式本身可在Exe项目上使用,因为目标窗口将按预期方式设置样式,但在类库项目上将失败.

希望你有主意:)

干杯!

Hi All!

Im facing problem to apply style in classlibrary project (project A) window which refers styles from another classlibrary assembly (project B).

The problem is kind of trivial. In project A window I have applied reference as usual in xaml using ResourceDictionary.MergedDictionaries (like in app.xaml when developing exe project).

If I put eg. button on that window and refer to my button style Style="{StaticResource myButtonStyle}" It works! Style will be applied on that button on desing time and ofcourse when calling that window from exe project. This will apply all components inside that window.

The problem comes if i style window itself I receive "recource could not be resolved"!?

The referred style itself works on Exe project because target window will be styled as expected but on class library project it fails.

Hope you got idea :)

Cheers!

推荐答案

我有点想通了.在窗口情况下,似乎应该使用"DynamicResource"而不是"StaticResource"来引用样式.不知道它的背后是什么...窗口内的控件可以通过"StaticResource"设置样式
I kindof figured it out. In window case it seems that I shoud refer to style using "DynamicResource" istead of "StaticResource". Dont know what is behind that... controls inside window can be styled by "StaticResource" though


这篇关于如何在ClassLibrary项目的wpf窗口上应用样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆