8

[vs2010とExpressionBlendv4を使用]

こんにちは-JoshSmithのコンセプトを使用して、WPFとBlendにいくつかの設計時データをロードしようとしています:http://joshsmithonwpf.wordpress.com/2010/04/07/assembly-level-initialization-at-design-time/

[AttributeUsage(AttributeTargets.Assembly)]
public class DesignTimeBootstrapperAttribute : Attribute
{
    public DesignTimeBootstrapperAttribute(Type type)
    {
        var dep = new DependencyObject();
        Debug.WriteLine("here..?");
        if (DesignerProperties.GetIsInDesignMode(dep))
        {
            // TODO: Design-time initialization…
            IBootstrapper instance = Activator.CreateInstance(type) as IBootstrapper;
            if (instance != null)
            {
                instance.Run();
            }
        }
    }
}

AppBootstrapperがMefBootstrapperを拡張するAssemblyInfo.csの私の属性を使用します。

[assembly: AssemblyCopyright("Copyright ©  2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: DesignTimeBootstrapper(typeof(AppBootstrapper))]

Blendのサンプルデータを使用したくありません。a)ObservableCollectionのデータを作成していないようです。b)定義上、デザインモードになっているため、状況は大きく変わりますが、'生成されたデータ' しない。

とにかく、何も起こっていないようです。

Q1:ブートストラッパーの設計時の初期化をデバッグするにはどうすればよいですか?Q2:View XAMLに追加のブレンド名前名/属性などが必要ですか?

(私のブートストラッパーでは、RunTimeServiceをDesignTimeServiceに置き換えたい別のモジュールを登録し、IServiceインターフェイスをエクスポートしています)。

TIA

4

1 に答える 1

3

これをデバッグするには:

  • VS2010でプロジェクトを開きます
  • アセンブリ属性コンストラクターにブレークポイントを設定します
  • Blend4の新しいインスタンスを開始します
  • VS2010から、[デバッグ]-> [プロセスにアタッチ]を使用し、[ブレンド]を選択します。
  • Blendに切り替えて、プロジェクトを開きます
  • サンプルデータを参照するXAMLファイルを開きます

また、Debug.WriteLineVS2010の出力ウィンドウに表示されるはずです。

属性メソッドを機能させることができない場合(私は自分で試していません)、 MVVM Lightからこのメソッド(私が使用したもの)を使用できます:

private bool? _isInDesignMode;

public bool IsInDesignMode
{
    get
    {
        if (!_isInDesignMode.HasValue)
        {
            var prop = DesignerProperties.IsInDesignModeProperty;
            _isInDesignMode =
                (bool)DependencyPropertyDescriptor
                .FromProperty(prop, typeof(FrameworkElement))
                .Metadata.DefaultValue;
        }

        return _isInDesignMode.Value;
    }
}
于 2011-01-19T03:55:00.323 に答える