2011-08-08 11 views
3

私はこのコンボボックス設計時のみエラー: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""/> 

を持っているそれは実行されます。できます。私は設計時にコンストラクタをスキップする静的クラスにいくつかのことを試してみました

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プロパティのゲッターで

答えて

2

トーマスの答え:静的コンストラクタで

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

作品。

3

、このコードを追加しよう:

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

まだ同じエラーが発生しています。 – Tyrsius

+0

[ここ](http://stackoverflow.com/questions/2030651/wpf-converter-casting-causes-visual-studio-designer-exception/2030861#2030861)で説明されているように、デザインモードでデバッグを試すことができます –

+0

とにかくバインディングを介してItemsSourceを設定することはできませんか?私はクリーナーになるだろう...静的リポジトリは悪いコードのにおいです。 –

関連する問題