Lightswitch - 如何重用现有资源?
我试图了解自定义 LightSwitch 应用程序的外观和感觉的最简化的方法是什么。
我已经构建了多个 WPF 和 Silverlight 应用程序,并且拥有一组通用的画笔、样式、故事板、图像等,并作为资源存储在专用的类库中。我没有任何自己的用户控件 - 只有样式、画笔、模板等,使它们看起来像是自定义的。
我选择在 LightSwitch 中构建下一个应用程序,并且希望保持与现有 WPF 和 Silverlight 应用程序相同的外观和感觉。因此,我想重新利用我现有的资源。
我探索了 Extensibility Toolkit,并且能够访问 LS 中使用的一些资源(例如画笔),但没有找到样式和模板在哪里。
问题#1:我可以在哪里合并我自己的资源字典以插入我自己的样式和模板?例如,如果我有一个按钮的隐式样式,我应该在哪里合并它?
在使用工具包的主题方法时,根据我的理解,需要执行以下操作才能看到应用于 LightSwitch 应用程序的修改:
a) 构建主题项目
b) 卸载以前安装的扩展
C) 重新启动 Visual Studio
d) 重新安装更新的主题扩展
e) 重新启动 Visual Studio
f) 加载 LightSwitch 解决方案并运行它
我错过了什么吗?我看到的解决方法是创建一个常规的 Silverlight 项目并使用我自己的资源库。一旦我对特定资源的外观感到满意并希望在 LightSwitch 中看到它,我会将其合并到主题中并执行上述痛苦的过程。
问题#2:如何快速更改主题并查看其实际效果?
请问,我缺少什么?我可能遗漏了一些东西,因为这不可能那么复杂,因为它在 SL 和 WPF 中很容易。我想做的就是将资源字典合并到 LS 应用程序中的某个位置,然后运行它来查看它们的运行情况。请帮忙! :)
I am trying to understand what is the most streamlined way of customizing the look and feel of my LightSwitch applications.
I have built several WPF and Silverlight applications, and have a common set of brushes, styles, storyboards, images, etc, stored as resources in a dedicated class library. I do not have any user controls of my own - just styles, brushes, templates, etc, that make them look customized.
I chose to build my next application in LightSwitch and I would like to keep the same look and feel as my existing WPF and Silverlight apps. Therefore, I would like to re-use my existing resources.
I explored the Extensibility Toolkit and was able to have access to some of the resources used in LS such as brushes, but did not find where the styles and templates are.
Question #1: Where can I merge my own resource dictionaries to plug in my own styles and templates? For instance, if I have a implicit style for a button, where do I merge it?
In using the toolkit's theme approach, from what I understand, one needs to do the following just to see a modification applied to a LightSwitch application:
a) Build the theme project
b) Uninstall the extension if previously installed
C) Restart Visual Studio
d) Reinstall the updated theme extension
e) Restart Visual Studio
f) Load the LightSwitch solution and run it
Am I missing something? A work around I see is to create a regular Silverlight project and use my own resource library. And once I am satisfied with the look of a particular resource and want to see it in LightSwitch I merge it in the theme and perform the painful process described above.
Question #2: how can I quickly change a theme and see it in action?
Please, what am I missing? I am likely missing something because this cannot be so complicated, since it is so easy in SL and WPF. All I want to do is merge my resource dictionaries somewhere in my LS app and run it to see them in action. Please help! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于Q1,简单地合并资源字典是不够的,您需要实现一个鲜为人知的接口,称为IThemeExtension,并用ThemeExtension属性来装饰类。没有太多关于它的文章,但是一旦你知道了这个不幸的名字(如果它被称为类似 StyleExtension 或 ControlStyleExtension 之类的东西,可能会不会那么混乱,但它的名字来自这样一个事实:它是主题的扩展,以附加控件样式的形式),非常简单。
IThemeExtension 接口只有一个要实现的方法:GetControlStyleResources,该方法必须返回 IEnumerable(Of Uri)。其目的是公开一个或多个 URI 值,每个值都指向包含控件样式定义的 ResourceDictionary(存储在 XAML 文件中)。
斜体文本引自我与 Tim Leung 合着的一本书,名为“Pro Visual Studio LightSwitch 2011 Development”,将于二月底发布。
如果您下载 Metro 主题的源代码,您将看到 Microsoft 如何使用该主题来更改控件样式以及画笔颜色。 (http://code.msdn.microsoft.com/LightSwitch-Metro-Theme-b1bfce24)
对于第二季度,当我创建主题时,为了测试它,我使用以下步骤。
步骤 4 中的额外部分只需针对尚未选择主题的项目执行。一旦完成,顺序就非常简单了。绝对不需要卸载/重新安装您的扩展。只需确保每次要测试它时增加版本号(例如从 1.0 到 1.0.1 等),&该扩展将升级其自身先前安装的版本。
我希望这一切有帮助。
For Q1, simply merging a resource dictionary isn't enough, you need to use implement a little-known interface called IThemeExtension, and decorate the class with the ThemeExtension attribute. There's not much written about it, but once you get by the unfortunate name (it probably would have been a lot less confusing if it had been called something like a StyleExtension, or a ControlStyleExtension, but its name comes from the fact that it’s an extension to a theme, in the form of additional control styles), it's pretty simple.
The IThemeExtension interface has only one method to implement, GetControlStyleResources, which must return an IEnumerable(Of Uri). Its purpose is to expose one or more URI values that each point to a ResourceDictionary (stored in a XAML file) that contain control style definitions.
The italicised text is quoted from a book that I'm writing with Tim Leung, called "Pro Visual Studio LighSwitch 2011 Development", due out at the end of February.
If you download the source for the Metro theme, you'll see how Microsoft is using the theme to make control style changes, as well as brush color changes. (http://code.msdn.microsoft.com/LightSwitch-Metro-Theme-b1bfce24)
For Q2, when I'm creating a theme, to test it I use the following steps.
The extra bits in step 4 only need to be done for a project that doesn't already have your theme selected. Once that's done, the sequence is very simple. There's absolutely no need to uninstall/reinstall your extension. Just make sure that you increment the version number (from say 1.0 to 1.0.1 etc) each time you want to test it, & the extension will upgrade the previously installed version of itself.
I hope all that helps.