wpf - 仅限设计时间错误 : WPF "StaticExtension" exception

标签 wpf visual-studio-2010

我有这个组合框

<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/

相关文章:

visual-studio-2010 - 如何找出导致内存泄漏的 Visual Studio 扩展?

windows - 如何在一个语句中评估两个函数?

c++ - 在 Qt Creator 中编译 Visual Studio 2010 项目?

c# - InvalidateVisual 是否以惰性方式工作?

.net - 如何为窗口的嵌套子项捕获 SourceUpdated?

c# - 如何使用触发器更改 TextBlock 的可见性?

以 MS Access 数据库作为数据源的 WPF 应用程序

visual-studio-2010 - 在 VS2010 中执行 BDD 的标准方法是什么?

c# - TextBox 限制为英文 20 个字符,简体中文 10 个字符

c# - 如何强制平滑呈现 WPF 控件?