部分声明,不得指定不同的基类

Nom*_*cio 9 c# wpf xaml

我知道在互联网上有关于此的信息,我已经搜索过了.但我仍然得到错误,有人能指出我做错了什么吗?

基类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace ProgramManagementV2.screens
{
    public abstract class AScreenUserControl : UserControl
    {
        public string GetScreenDescriptionName()
        {
            return "No name yet!";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

MainUserControl.xaml

<UserControl x:Class="ProgramManagementV2.screens.MainUserControl"
             xmlns:we="clr-namespace:ProgramManagementV2.screens"
             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" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <TextBlock Height="23" HorizontalAlignment="Center" Name="textBlock1" Text="asdfasdf" VerticalAlignment="Center" />
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

MainUserControl.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace ProgramManagementV2.screens
{
    /// <summary>
    /// Interaction logic for MainUserControl.xaml
    /// </summary>
    public partial class MainUserControl : AScreenUserControl
    {
        public MainUserControl()
        {
            InitializeComponent();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如你所见,我正在补充

xmlns:we="clr-namespace:ProgramManagementV2.screens"
Run Code Online (Sandbox Code Playgroud)

用户控制xml但我仍然收到错误:

"ProgramManagementV2.screens.MainUserControl"的部分声明不得指定不同的基类

谁能向我解释我做错了什么?

H.B*_*.B. 22

通过使用<UserControl ...您声明基类UserControl,您需要将其更改为

<we:AScreenUserControl x:Class="ProgramManagementV2.screens.MainUserControl" ...
Run Code Online (Sandbox Code Playgroud)

但是UserControls我认为只允许一个级别的继承,至少如果AScreenUserControl有一个XAML,这肯定是行不通的.


Rhy*_*ous 5

这样做:

<we:AScreenUserControl x:Class="ProgramManagementV2.screens.MainUserControl"
             xmlns:we="clr-namespace:ProgramManagementV2.screens"
             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"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <TextBlock Height="23" HorizontalAlignment="Center" Name="textBlock1" Text="asdfasdf" VerticalAlignment="Center" />
    </Grid>
</we:AScreenUserControl>
Run Code Online (Sandbox Code Playgroud)

  • "我们:AScreenUserControl不能是XAML文件的根,因为它是使用XAML定义的" (2认同)