简体   繁体   English

为什么UserControl无法继承UserControl以外的其他内容

[英]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. 由于DraggableControl继承自UserControl,因此UserControl1应该能够从DraggableControl继承。 I don't understand why visual studio does not let me compile that code. 我不明白为什么Visual Studio不让我编译该代码。

It's probably because you didn't change the XAML declaration accordingly. 可能是因为您没有相应地更改XAML声明。

Answers to this question may help. 回答这个问题可能会有所帮助。

However, it looks like you can't derive from a class that has XAML :-( 但是,似乎您不能从具有XAML的类派生:-(

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

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