Silverlight 4:无需使用 Toolkit 即可更改整个应用程序的主题/样式

发布于 2024-09-24 19:41:51 字数 331 浏览 2 评论 0原文

我们正在着手实施我们的第一个 Silverlight 项目,该项目来自 WPF。这是一个相对简单的 Web 门户,考虑到我们使用 WPF 工具包的经验,我们希望避免引用 Silverlight 工具包。

我不太擅长编码,并且有几个与主题相关的问题:

  • 隐式样式使这变得更容易。很明显,您可以直接切换资源词典来更改主题。如何在不依赖工具包的情况下执行此操作?

  • 如何将样式应用到整个应用程序(例如在 WPF 中),而不是将样式包装在主题容器中?我看到您可以使用一个 ApplicationThemeURI,但这需要工具包。

谢谢。

We are embarking on our first Silverlight project, coming from WPF. It's a relatively simple web portal and we would like to avoid references to the Silverlight Toolkit, given our experience with the WPF toolkit.

I'm not much of a coder and have a couple questions related to themes:

  • Implicit styles make this easier. It seems clear you could just switch out resource dictionaries to change your theme. How do I do this without relying on the Toolkit?

  • How do I apply the styles to the entire application, like in WPF, instead of wrapping things in the theme containers? I see there is an ApplicationThemeURI you can use, but that requires the toolkit.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱给你人给你 2024-10-01 19:41:51

在 silverlight 4 中将样式应用到整个应用程序是一项简单的任务。将此代码放入 App.xaml 或 theme/generic.xaml 中:

<!-- Sample style for each button in the application -->
<Style TargetType="Button">
</Style>

本文可以帮助您:
http://www.silverlightshow.net/items/Implicit-Styles -in-Silverlight-4.aspx
 

您可以通过以下方式更改资源字典:

var dict = Application.Current.Resources.MergedDictionaries.FirstOrDefault(rd => rd.Source == new Uri("Dictionary1.xaml", UriKind.Relative));
if (dict != null)
     dict.Source = new Uri("Dictionary2.xaml", UriKind.Relative);

Applying style to whole app is a simple task in silverlight 4. Put this code in App.xaml or themes/generic.xaml:

<!-- Sample style for each button in the application -->
<Style TargetType="Button">
</Style>

This article could help you:
http://www.silverlightshow.net/items/Implicit-Styles-in-Silverlight-4.aspx  

You can change resource dictionary by this way:

var dict = Application.Current.Resources.MergedDictionaries.FirstOrDefault(rd => rd.Source == new Uri("Dictionary1.xaml", UriKind.Relative));
if (dict != null)
     dict.Source = new Uri("Dictionary2.xaml", UriKind.Relative);
各自安好 2024-10-01 19:41:51

只是关于 Siverlight 工具包的注释。上次我使用 WPF 工具包(那是不久前)时,我的印象是它或多或少是可选的。我不会说 Silverlight Toolkit 也是如此。它添加了大量重要的功能,您自己很难实现这些功能,虽然它不是没有错误,但它非常可靠。我无法保证它的各个方面,但我们在大型 Silverlight 项目(约 30K 行代码)中广泛使用它,并且我们发现它不可或缺。除非您意识到您的项目会遇到的具体问题,否则我建议您重新考虑不使用它的决定。

Just a note on the Siverlight Toolkit. The last time I used the WPF Toolkit (which was a while ago), I got the impression that it was more-or-less optional. I wouldn't say that the same is true of the Silverlight Toolkit. It adds a great deal of important functionality that would be difficult to implement on your own, and while it's not bug-free, it's pretty reliable. I can't vouch for every aspect of it, but we're using it extensively in a large Silverlight project (~30K lines of code), and we find it indispensable. Unless you're aware of specific issues that your project would encounter, I would recommend that you rethink your decision not to use it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文