简体   繁体   中英

Why is it not possible for a UserControl to inherit from something else than UserControl

I need all my user controls to have some similar functionality. So my user control it is as:

using System.Windows.Controls;


namespace WpfApplication26
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
    }
}

ok now I want to make that control inherit from a base class where I have all my functionality as a result I now have something like:

在此处输入图片说明

I posted a picture to show you guys the error that I am getting. UserControl1 should be able to inherit from DraggableControl Since DraggableControl inherits from UserControl. I don't understand why visual studio does not let me compile that code.

It's probably because you didn't change the XAML declaration accordingly.

Answers to this question may help.

However, it looks like you can't derive from a class that has XAML :-(

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