仅设计时错误:WPF“StaticExtension"例外 [英] DesignTime only Error: WPF "StaticExtension" exception

查看:23
本文介绍了仅设计时错误:WPF“StaticExtension"例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个组合框

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

它运行.有用.除了在设计器中,由于错误,它不会让我做任何事情:

It runs. It works. Except in the designer, which won't let me do anything because of the error:

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.

我在静态类中尝试了几种方法来在设计时跳过构造函数,但都没有修复错误:

I have tried several things in the static class to skip the constructor in designtime, none of which fix the error:

if (LicenseManager.UsageMode == LicenseUsageMode.DesignTime)
if (DesignerProperties.GetIsInDesignMode(this))
if (System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio"))

如果其中任何一个为真,则在构造函数中返回.仍然收到错误.

And returning in the constructor if any of these are true. Still getting the error.

编辑:不确定它是否有任何区别,但静态存储库类使用 EF4 从数据库中获取.

Edit: Not sure if it makes any difference, but the static repository class uses EF4 to get from a database.

Edit2:也试过 ItemsSource {Binding} 到静态列表,仍然得到同样的错误.请注意,将其称为存储库是用词不当,列表在启动时加载并且从未更改.下面的答案不起作用,仍在尝试解决这个问题.

Edit2: Also tried ItemsSource {Binding} to the static lists, still get the same error. Note, calling it a repository is a misnomer, the lists are loaded on startup and never changed. Below answer does not work, still trying to figure this out.

Edit3:Thomas 对调试设计模式的建议不可行.我使用的是 VS2010 Express,并且工具菜单没有附加到进程选项.我仍然不知道为什么这会破坏设计器并在运行时工作.

Edit3: Thomas' Suggestion to debug design mode wasn't doable. I am using VS2010 Express, and the tools menu does not have an attach to process option. I still don't know why this breaks the designer and works in runtime.

推荐答案

Thomas answer:

Thomas answer:

if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
return null;

在静态构造函数中工作.

Works in the static constructor.

这篇关于仅设计时错误:WPF“StaticExtension"例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆