ASP.NET 中的主皮肤文件
我的项目有多个不同颜色的主题。
我需要使用特定字体/大小/等对某些文本框进行皮肤处理。[无色差]
目前,我将
添加到每个主题下的所有 .skin 文件中。 有没有办法将这个文本框皮肤放在一个地方,就像主皮肤一样?
My project has multiple themes with different colors.
I need to skin certain textboxes with a specific font/size/etc.[no color difference]
Currently, I add <asp:TextBox SkinID="skinned" runat="server".../>
to all .skin files under each theme.
Is there a way to put this textbox skin in one place, like a master skin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET 主题 实现中缺乏继承或级联是一个不幸的限制,但并未受到太多关注。如果您希望为所有主题提供全局皮肤(而不更改控件定义本身),您有两个选择:
选项#1:使用 VirtualPathProvider
(这样做的缺点是,如果没有基于反射的解决方法。)
您可以定义一个 Global.skin 文件在一个特殊的全球主题下,保留共享的皮肤;您还将在所有其他主题下创建一个占位符 Global.skin 文件:
在 VirtualPathProvider 中,您将重新路由对 App_Themes\*\Global.skin 的所有请求到App_Themes\Global\Global.skin。
选项#2:使用构建后任务
这是对上述解决方案的修正,避免了预编译网站的限制;您可以通过 ms-build 任务在构建后应用它,而不是在运行时进行重新路由,该任务只需将 Global\Global.skin 传播到所有其他主题文件夹。
我已经成功地使用了这两个选项。
The lack of inheritance or cascading in the ASP.NET Themes implementation is an unfortunate limitation that doesn't receive a lot of attention. In scenarios where you wish to have a global skin available to all themes (without changing the control definition itself), you have two options:
Option #1: Use a VirtualPathProvider
(The downside of this is that you can't use it on precompiled websites without a reflection-based workaround.)
You can define a Global.skin file under a special Global theme where shared skins are kept; you will also create a placeholder Global.skin file under all other themes as well:
In the VirtualPathProvider you would then re-route all requests for App_Themes\*\Global.skin to App_Themes\Global\Global.skin.
Option #2: Use a Post-Build Task
This is an amendment to the above solution that avoids the precompiled websites limitation; instead of doing the re-route at runtime, you can apply it post-build via an ms-build task that simply propagates Global\Global.skin to all other theme folders.
I've used both options successfully.
您需要在每个主题下列出它,但只需为每个主题列出一个控件定义。如果您希望外观成为控件的默认行为,请指定不带 SkinID 属性的定义。
You will need to list it under each theme, but you only need to list one control definition per theme. If you want a skin to be the default behavior for a control, specify the definition without a SkinID property.