How to use d:DesignInstance with types that don't have default constructor?

前端 未结 3 1159
轮回少年
轮回少年 2020-12-13 14:03

I am binding a textbox to an object, like so:

  

        
3条回答
  •  悲&欢浪女
    2020-12-13 14:25

    The default constructor is required for a type to be instantiated in XAML. As a workaround you can simply create a subclass of TaskVM that will have the default contructor and use it as a design time data context.

    
    
    

    Another alternative is to set d:IsDesignTimeCreatable to False and a substitute type will be created for you at runtime (using your TaskVM type as a "shape").

    
    
    

提交回复
热议问题