Windows phone 7 如何在WindowsPhone7中绑定到静态类的字段?
是否有任何方法可以绑定到WindowsPhone7中静态类中的字段 在WPF中,我可以编写如下内容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
<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 behindthis.listbox.ItemsSource=TestStatic.Items
必须在code behind中这样做有点糟糕-尤其是Microsoft总是告诉我们xaml是解决一切问题的方法。我知道你的意思。最近,我发现自己慢慢地回到了我的旧习惯:(