【问题标题】:Cannot create inherited usercontrol in WPF, base control "does not exist" in local namespace无法在 WPF 中创建继承的用户控件,本地命名空间中的基本控件“不存在”
【发布时间】:2019-04-26 16:58:16
【问题描述】:

我尝试在 WPF 中创建一个自定义的用户控件“UserControl1”,它继承自一个基类。除其他外,我在 XAML 中收到此错误: 错误 XDG0008 名称“ControlBase”在命名空间“clr-namespace:Temp”中不存在。 我在 DesignHeight & Width 处也遇到错误

ControlBase 类在 VS 自动补全中可用。

ControlBase 类在命名空间 Temp 中定义。

我已尝试更改基类的关键字,例如添加部分关键字。

UserControl1.xaml:

<local:ControlBase x:Class="Temp.UserControl1"
             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:Temp"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>

    </Grid>
</local:ControlBase>

UserControl1.xaml.cs:

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

ControlBase.cs:

using System.Windows.Controls;

namespace Temp
{
    public class ControlBase : UserControl
    {
        public ControlBase() { }
    }
}

我希望 UserControl1 从 ControlBase 继承而不会出现编译器错误。

【问题讨论】:

标签: c# wpf inheritance namespaces user-controls


【解决方案1】:

我不知道我做了什么,但它自己修复了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 2016-08-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    相关资源
    最近更新 更多