WPF 中的设计时数据
[使用vs2010 &表达式混合 v4]
嗨 - 尝试在 WPF 和 Blend 中加载一些设计时数据,使用 Josh Smith 的概念: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();
}
}
}
}
我的属性位于 AssemblyInfo.cs 中,其中 AppBootstrapper 扩展了 MefBootstrapper。
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: DesignTimeBootstrapper(typeof(AppBootstrapper))]
我不想使用 Blend 示例数据,a) 因为它似乎没有为 ObservableCollection 创建数据,b) 根据定义,我处于设计模式,所以事情会发生很大变化,但我的“生成的数据” '不会。
无论如何,似乎什么也没有发生。
问题 1:如何调试引导程序的设计时初始化? 问题 2:我的视图 XAML 中是否需要额外的混合命名空间/属性等?
(在我的引导程序中,我只是注册一个不同的模块,我想用 DesignTimeService 替换 RunTimeService,导出 IService 接口)。
TIA
[using vs2010 & expression blend v4]
Hi - trying to load up some design time data in WPF and Blend, using Josh Smith's concept here: http://joshsmithonwpf.wordpress.com/2010/04/07/assembly-level-initialization-at-design-time/
e.g.
[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();
}
}
}
}
With my attribute here in AssemblyInfo.cs, where AppBootstrapper extends MefBootstrapper.
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: DesignTimeBootstrapper(typeof(AppBootstrapper))]
I don't want to use the Blend sample data, a) as it doesn't seem to create data for ObservableCollection and b) I'm in design mode by definition, so things will change quite a lot, but my 'generated data' will not.
Anyway, nothing seems to be happening.
Q1: How is it possible to debug the design time initialisation of my bootstrapper?
Q2: Do I need additional blend namespaces/ attributes etc in my View XAML?
(In my bootstrapper I'm just registering a different module where I want to replace RunTimeService with a DesignTimeService, exporting the IService interface).
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要调试它:
此外,任何
Debug.WriteLine
都应该出现在 VS2010 输出窗口中。如果你无法让属性方法起作用(我自己没有尝试过),你可以使用 MVVM 轻量级:
To debug this:
Also, any
Debug.WriteLine
should appear in the VS2010 output window.If you can't get the attribute method to work (I haven't tried it myself), you can use this method (which I have used) from MVVM Light: