仅设计时间错误:WPF";“静态扩展”;例外
我有这个组合框仅设计时间错误:WPF";“静态扩展”;例外,wpf,visual-studio-2010,Wpf,Visual Studio 2010,我有这个组合框 <ComboBox Name="company" Width="120" HorizontalAlignment="Right" Margin="5" IsSynchronizedWithCurrentItem="True" ItemsPanel="{DynamicResource Virtualized}" ItemsSo
<ComboBox Name="company" Width="120"
HorizontalAlignment="Right" Margin="5"
IsSynchronizedWithCurrentItem="True"
ItemsPanel="{DynamicResource Virtualized}"
ItemsSource="{x:Static local:Repository.Customers}"
SelectedItem="{Binding Path=SelectedCustomer}"
DisplayMemberPath="CM_FULL_NAME""/>
细部
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
我在静态类中尝试了几种方法来跳过designtime中的构造函数,但没有一种方法可以修复错误:
ArgumentException was thrown on "StaticExtention": Exception has been thrown by the target of an invocation.
if (LicenseManager.UsageMode == LicenseUsageMode.DesignTime)
if (DesignerProperties.GetIsInDesignMode(this))
if (System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio"))
如果其中任何一个为真,则返回构造函数。还是会出错
编辑:不确定它是否有任何区别,但静态存储库类使用EF4从数据库获取数据
Edit2:也尝试了将ItemsSource{Binding}添加到静态列表,但仍然得到相同的错误。请注意,将其称为存储库是一种误称,列表在启动时加载,从未更改。下面的答案不起作用,仍在试图弄清楚这一点
Edit3:托马斯关于调试设计模式的建议不可行。我使用的是VS2010 Express,“工具”菜单没有“附加到进程”选项。我仍然不知道为什么这会破坏设计器并在运行时工作。在
Customers
属性的getter中,尝试添加以下代码:
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
return null;
托马斯回答:
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
return null;
在静态构造函数中工作。您可以尝试在设计模式下进行调试,正如所解释的,您不能通过绑定设置ItemsSource吗?我会更干净。。。静态存储库是一种糟糕的代码味道。我不确定你的意思是什么,我使用的是基于另一个stackoverflow答案的静态类。但是,ItemsSource=“{Binding Source={x:Static local:Repository.Customers}}”仍然会导致相同的错误。我的意思是,您的ItemsSource应该来自DataContext上的绑定,而不是来自静态类。为什么?这些项目在启动时被检索,重复使用数十次,并且永远不会更改。