我知道互联网上有关于此的信息,我已经搜索了。但是我仍然遇到错误,有人可以指出我做错了什么吗?
基类:
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!";
}
}
}
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>
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();
}
}
}
如您所见,我正在添加
xmlns:we="clr-namespace:ProgramManagementV2.screens"
到用户控件xml,但仍然出现错误:
谁能向我解释我做错了什么?
最佳答案
通过使用<UserControl ...
,您将基类声明为UserControl
,则需要将其更改为
<we:AScreenUserControl x:Class="ProgramManagementV2.screens.MainUserControl" ...
但是,我认为
UserControls
仅允许一种继承级别,至少如果AScreenUserControl
具有XAML,则这肯定不会起作用。关于c# - 部分声明,不能指定不同的基类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12039970/