如何使用 Phone7 Silverlight 应用程序的 {x:Static ...} 扩展?
我正在编写一个 Phone 7 应用程序,我想在标记中引用常量值。我相信应该这样做的方式是通过 x:Static 。
然而,Visual Studio 一直声称它不了解 x:static
。这里的秘诀是什么?我有以下内容:
<phone:PhoneApplicationPage
...
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
...
<Image Height="{x:Static App.ImageHeight}" ... />
...
当然:
public partial class App : Application
{
public const double ImageHeight = 100;
...
错误消息是“未找到类型‘x:Static’。请验证...”。
I'm writing a Phone 7 app and I would like to reference constant values in markup. I believe the way one is supposed to do this is via x:Static.
However, Visual Studio keeps claiming it has no knowledge of x:static
. What is the secret sauce here? I have the following:
<phone:PhoneApplicationPage
...
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
...
<Image Height="{x:Static App.ImageHeight}" ... />
...
And of course:
public partial class App : Application
{
public const double ImageHeight = 100;
...
The error message is "The type 'x:Static' was not found. Verify that...".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
x:Static
仅在 WPF 中可用 - 用于浏览器的 Silverlight 和用于 Windows Phone 7 的 Silverlight 均不支持此标记扩展。通常的解决方法是创建一个(非静态)类,该类的属性只需包装所需的静态属性,然后创建该实例作为资源并以这种方式绑定它。
示例*:
在资源 (app.xaml) 中:
在使用它的 xaml 中:
*此示例取自 在从 Enum 填充的 ListPicker 中使用本地化字符串
x:Static
is only available in WPF - neither Silverlight for the browser nor Silverlight for Windows Phone 7 support this markup extension.The usual workaround is to create a (non-static) class that has properties which simply wrap the static properties you want, and create an instance of that as a Resource and bind against it that way.
Example*:
In the resources (app.xaml):
In the xaml where it's used:
*This example is taken from an answer in Using localized strings in a ListPicker populated from Enum