那么标题应该很好地解释问题。考虑我创建一个新的UserControl
,但是在我的应用程序中,许多这些元素共享一个通用代码,并且它们是用户控件“子组”的一部分。使用Visual Studio设计器时继承UserControl基类的错误
合乎逻辑的是在生成的CustomUserControl
和UserControl
之间“插入”一个类;
一种近乎:
public abstract class CommonCustomControl : UserControl
{
public CommonCustomControl(int v, string other) {
}
}
public partial class CustomUserControl : CommonCustomControl
{
CustomUserControl(int v, string other) : base(v, other) {
}
}
现在有了这个问题,是该类只是“局部”由Visual Studio生成。因此更改生成的CustomUserControl
类会给出错误:
“基类与其他部分中声明的不同”
如何防止此错误?虽然仍然能够在Visual Studio的GUI设计器中真正设计我的用户控制元素?
我已经试过了this question提供的答案。但它似乎根本不起作用。 (也许自那时候谈到winforms而不是WPF版本)
[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<InterfaceHandler, UserControl>))]
public abstract class CommonCustomControl : UserControl
{
private readonly int _v;
private readonly string _other;
public CommonCustomControl(int v, string other) {
_v = v;
_other = other;
}
}
public partial class CustomUserControl : CommonCustomControl
{
public CustomUserControl(int v, string other) : base(v, other) {
}
}
出了什么问题?
啊我也可以做这样的事情。 – paul23
很容易错过... –