简体   繁体   English

xaml设计时需要实例还是避免实例?

[英]Design-time xaml requires instance or avoid it?

I have a problem I can not find how to solve the issue of the Design-time XAML, because it tells me: " Object reference not set an instance of an object ". 我有一个问题,我找不到如何解决设计时XAML的问题,因为它告诉我:“ 对象引用未设置对象的实例 ”。

Visual capture: 视觉捕捉: 在此处输入图片说明

Here my fill of the list from Partial Class MainPage: 这是我在Partial Class MainPage中填写的列表: 在此处输入图片说明

However, at compile time, it works correctly: 但是,在编译时,它可以正常工作: 在此处输入图片说明

And after runtime, it works.... 在运行时,它可以工作...。

And my namespace of ViewModels where load return the list of " Scenario " class, instantiate not testify again as only get it built above. 而我的ViewModels命名空间(加载返回“ Scenario ”类的列表)在实例化时不再进行验证,因为仅在上面构建。 And I want to instantiate all my MainPage XAML when I just need a static list. 当我只需要一个静态列表时,我想实例化所有MainPage XAML。

Any way to solve this without instantiating the list in the constructor? 有什么方法可以解决此问题而无需在构造函数中实例化列表? Or what good practice recommend? 还是推荐什么好的做法? I want to work in Design-Time. 我想在设计时工作。

EDIT: To clarify, in the class: MainPage my control: MainWindow (sealed class, the capture is the partial kind of my sealed class) is where I think my static variable of type " MainPage ", with the builder to " this " and that let me get elements. 编辑:要澄清一下,在类中:MainPage我的控件:MainWindow(密封类,捕获是我的密封类的部分类型)是我认为类型为“ MainPage ”的静态变量,其中生成器为“ this ”,并且让我得到元素。

在此处输入图片说明

Thousand Thanks. 千恩万谢。

Has MainPage.Current value? MainPage.Current值吗? I don't think... (like Application.Current is null in Design-time) 我不认为...(例如Application.Current在设计时为null


Edit: why do not use design time datacontext? 编辑:为什么不使用设计时数据上下文? d:DataContext d:DataContext的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM