简体   繁体   中英

Wpf usercontrol base, cannot create an instance

I add an Usercontrol base class

my Base Class

 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;
        }
    }

but the design does not shown

在此处输入图片说明

Browsing around some of the other questions, I found some of the reasons this can happen

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

  1. Suround the code in your constructor with this:
if(!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
{
   //code producing exception         
}
  1. The base class is of the abstract type
  2. An exception is thrown in your constructor while loading the custom control. This goes back to 1.

Please share the stacktrace for us to help more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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