我有这个组合框
<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""/>
它运行。有用。除了在设计器中,由于错误不允许我做任何事情:
ArgumentException was thrown on "StaticExtention": Exception has been thrown by the target of an invocation.
细节
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
我在静态类中尝试了几种方法来在设计时跳过构造函数,但都没有修复错误:
if (LicenseManager.UsageMode == LicenseUsageMode.DesignTime)
if (DesignerProperties.GetIsInDesignMode(this))
if (System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio"))
如果其中任何一个为真,则在构造函数中返回。仍然出现错误。
编辑:不确定是否有任何区别,但是静态存储库类使用 EF4 从数据库中获取。
Edit2:也试过 ItemsSource {Binding} 到静态列表,仍然得到同样的错误。请注意,将其称为存储库是用词不当,列表在启动时加载并且从未更改。下面的答案不起作用,仍在尝试解决这个问题。
Edit3:Thomas 关于调试设计模式的建议不可行。我正在使用 VS2010 Express,工具菜单没有附加到进程选项。我仍然不知道为什么这会破坏设计器并在运行时工作。
最佳答案
在 Customers
属性的 getter 中,尝试添加以下代码:
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
return null;
关于wpf - 仅限设计时间错误 : WPF "StaticExtension" exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6988863/