Wpf用户控件库,无法创建实例

问题描述 投票:2回答:1

我添加了一个Usercontrol基类

我的基础班

 public class UserControlBase : UserControl
    {
        protected IAppLogic app;
        public  MainWindow CurrentWindow{
            get{
                return (App.Current.MainWindow as MainWindow);
            }
        }



        public UserControlBase()
        {
            var _app = IoC.Kernel.Get<IAppLogic>();
            this.app = _app;
        }

        public void MainNavigate(Pages.PageBase p)
        {
            CurrentWindow.MainFrame.Content = p;
        }
    }

但未显示设计

enter image description here

c# wpf
1个回答
0
投票

浏览其他一些问题,我发现了发生这种情况的一些原因

Q1 WPF Designer “Could not create an instance of type”

  1. 在构造函数中使用以下代码:
if(!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
{
   //code producing exception         
}
  1. 基类是抽象类型
  2. 加载自定义控件时,构造函数中引发了异常。返回到1。

请共享堆栈跟踪信息以帮助我们提供更多帮助。

© www.soinside.com 2019 - 2024. All rights reserved.