【发布时间】:2017-02-27 09:23:31
【问题描述】:
好吧,标题实际上应该很好地解释了这个问题。假设我创建了一个新的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) {
}
}
出了什么问题?
【问题讨论】:
标签: c# wpf visual-studio inheritance user-controls