C# WPF UserControl继承另一个UserControl

C# WPF UserControl继承另一个UserControl,c#,wpf,user-controls,C#,Wpf,User Controls,我正试图以中提到的方式继承WPF中的usercontrol 名称空间DMS.Presentation { /// ///WorkSpaceViewControl的交互逻辑 /// 公共抽象类WorkSpaceViewControl:UserControl { 公共工作空间视图控件() { 初始化组件(); } 私有void InitializeComponent() { } } } 到目前为止,代码没有给出任何错误。但当我在新的usercontrol中继承它时: namespace D

我正试图以中提到的方式继承WPF中的usercontrol

名称空间DMS.Presentation
{
/// 
///WorkSpaceViewControl的交互逻辑
/// 
公共抽象类WorkSpaceViewControl:UserControl
{
公共工作空间视图控件()
{
初始化组件();
}
私有void InitializeComponent()
{
}
}  
}
到目前为止,代码没有给出任何错误。但当我在新的usercontrol中继承它时:

namespace DMS.Presentation
{
    /// <summary>
    /// Interaction logic for AnimalWorkSpaceView.xaml
    /// </summary>
    public partial class AnimalWorkSpaceView : WorkSpaceViewControl
    {
        public AnimalWorkSpaceView()
        {
            InitializeComponent();
        }

    }

}
名称空间DMS.Presentation
{
/// 
///AnimalWorkSpaceView.xaml的交互逻辑
/// 
公共部分类AnimalWorkSpaceView:WorkSpaceViewControl
{
公共动物工作空间视图()
{
初始化组件();
}
}
}
它的XAML文件是:

//I have tried both WorkSpaceViewControl:UserControl and UserControl:WorkSpaceViewControl here


<UserControl:WorkSpaceViewControl x:Class="DMS.Presentation.WorkSpaceViewControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:DMS.Presentation"
             xmlns:WorkSpaceViewControl="clr-namespace:DMS.Presentation"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

</UserControl:WorkSpaceViewControl>
//我在这里尝试了WorkSpaceViewControl:UserControl和UserControl:WorkSpaceViewControl

我得到一条消息,部分修饰符不存在。存在WorkSpaceViewControl的另一部分声明。那么,我应该如何实施它,哪里出了问题?从一月份开始,我的整个项目就因为继承瓶颈而陷于停顿。非常感谢您的帮助。

根据您参考的答案,您派生的
UserControl
XAML应该更像这样:

<local:WorkSpaceViewControl x:Class="DMS.Presentation.AnimalWorkSpaceView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:local="clr-namespace:DMS.Presentation"
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="300">
</local:WorkSpaceViewControl>

您声明了两个不同的XML名称空间,
local
WorkSpaceViewControl
,都引用了
“clr名称空间:DMS.Presentation”
。您只需要其中一个(因此我保留了
local
,这更惯用),并且您需要使用名称空间来限定类型名
WorkSpaceViewControl

因此,XAML声明以

<local:WorkSpaceViewControl x:Class="DMS.Presentation.AnimalWorkSpaceView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:local="clr-namespace:DMS.Presentation"
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="300">
</local:WorkSpaceViewControl>