如何在 Windows Phone 7 中使用全局样式?
我想在 WP7 中使用全局样式,例如:
<Style TargetType="Button">
//some code here
</Style>
问题是此代码似乎无法在 WP7 中工作。
我知道如何将 x:Key 添加到样式中,然后如何将其作为 StaticResource 引用,但这不是我的情况。我想要一个全球风格。
I want to use a global Style in WP7, something like:
<Style TargetType="Button">
//some code here
</Style>
The problem is that this code does not seem to work in WP7.
I know how to add x:Key to the Style and after that how to reference it as a StaticResource, but this is not my case. I want a global Style.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果我创建一个像这样的应用程序范围(全局)样式:
那么我可以这样引用它:
If I create an application wide (global) style like this:
Then I can refer to it like this:
如果我理解正确的话,您想在 WP7 中使用隐式样式。
如果是这样,请记住:隐式样式是 Silverlight 4(和 WPF)的一项功能:Windows Phone 7 基于 Silverlight 3+(添加了一些 Silverlight 4 功能)。
由于 Silverlight 3 中没有隐式样式,这意味着也无法在 Windows Phone 7 中使用它们。
因此,如果您想在 WP7 中实现某种全局样式,我建议您按照 Matt Lacey 的建议尝试使用 StaticResource 的方法。
If I understand you correctly you want to use Implicit Styles in WP7.
If so then have in mind that: Implicit Styles are a feature of Silverlight 4 (and WPF): Windows Phone 7 is based on Silverlight 3+(with a few Silverlight 4 features added).
Since there’s no Implicit Styles in Silverlight 3 this mean that there is no way to use them in Windows Phone 7 as well.
So, if you want to implement some kind of global Style in WP7, I would suggest that you try the approach with StaticResource as Matt Lacey suggested.
在 WP7 Mango 中,它支持隐式样式功能。在mango MS中,将silvelight 3升级到silverlight 4。所以它工作得很好,
尝试这个链接:http://www.windowsphonegeek.com/articles/Windows-Phone-7-Mango-Implicit-Styles
In WP7 Mango it supports the implicit styling feature. In mango MS upgraded silvelight 3 to silverlight 4. So it works perfectly
try this link : http://www.windowsphonegeek.com/articles/Windows-Phone-7-Mango-Implicit-Styles
如果您希望所有按钮使用相同的样式,则必须创建一个实现该样式的按钮基类,然后从中继承所有按钮。
您可以使用用户控件或自定义控件来执行此操作。用户控制可能更容易。
If you want all your buttons to use the same style, you will have to create a base button class that implements the style then inherit all your buttons from that.
You can do this with a user control or a custom control. A user control is probably easier.