小编Ian*_*Ian的帖子

在WPF中设计时间数据

[使用vs2010和表达式混合v4]

嗨 - 尝试在WPF和Blend中加载一些设计时数据,使用Josh Smith的概念:http://joshsmithonwpf.wordpress.com/2010/04/07/assembly-level-initialization-at-design-time/ eg

[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();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的属性在AssemblyInfo.cs中,AppBootstrapper扩展了MefBootstrapper.

[assembly: AssemblyCopyright("Copyright ©  2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: DesignTimeBootstrapper(typeof(AppBootstrapper))]
Run Code Online (Sandbox Code Playgroud)

我不想使用Blend样本数据,a)因为它似乎没有为ObservableCollection创建数据而b)我按照定义处于设计模式,因此事情会发生很大变化,但我的'生成的数据' 将不会.

无论如何,似乎没有任何事情发生.

Q1:如何调试我的bootstrapper的设计时初始化?Q2:我的View XAML中是否需要额外的混合命名空间/属性等?

(在我的引导程序中,我只是注册了一个不同的模块,我想用DesignTimeService替换RunTimeService,导出IService接口).

TIA

wpf design-time mvvm expression-blend

8
推荐指数
1
解决办法
1760
查看次数

标签 统计

design-time ×1

expression-blend ×1

mvvm ×1

wpf ×1