Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 7 如何在WindowsPhone7中绑定到静态类的字段?_Windows Phone 7 - Fatal编程技术网

Windows phone 7 如何在WindowsPhone7中绑定到静态类的字段?

Windows phone 7 如何在WindowsPhone7中绑定到静态类的字段?,windows-phone-7,Windows Phone 7,是否有任何方法可以绑定到WindowsPhone7中静态类中的字段 在WPF中,我可以编写如下内容 <ListBox ItemsSource="{Binding Source={x:Static local:TestStatic.Items}}" /> 其中TestStatic定义为 public static class TestStatic { public static IEnumerable<string> Items { get { ret

是否有任何方法可以绑定到WindowsPhone7中静态类中的字段

在WPF中,我可以编写如下内容

<ListBox ItemsSource="{Binding Source={x:Static local:TestStatic.Items}}" />

其中TestStatic定义为

public static class TestStatic
{
    public static IEnumerable<string> Items
    { get { return new string[] { "Item A", "Item B", "Item C" }; } }
}
公共静态类TestStatic
{
公共静态可数项
{get{返回新字符串[]{“项A”、“项B”、“项C”};}
}
但这在WP7中不起作用,错误是“找不到类型“x:Static…”


有人对此有什么建议吗?

您不能在WP7中使用静态标记扩展(我觉得这很烦人)。您需要使用abhinav建议的解决方法。

为什么不在代码隐藏中执行此操作
ItemsSource=“{Binding}”
和在code behind
this.listbox.ItemsSource=TestStatic.Items
必须在code behind中这样做有点糟糕-尤其是Microsoft总是告诉我们xaml是解决一切问题的方法。我知道你的意思。最近,我发现自己慢慢地回到了我的旧习惯:(