次のWPF UserControlはDataTypeWholeNumberという名前で動作します。WPF UserControlはどのようにしてWPF UserControlを継承できますか?
今私はなど、ユーザーコントロールは、DataTypeDateTimeとDataTypeEmailと呼ばれるようにしたい
依存関係プロパティの多くは、これらすべてのコントロールによって共有されるので、私はに彼らの共通のメソッドを入れたいですBaseDataTypeこれらの各UserControlsにこの基本型を継承させます。私はそれを行うとき
はしかし、私はエラーが表示されます。部分的な宣言は異なる基底クラスを持っていないかもしれません。
UserControlsで継承を実装すると、どのように共有機能がすべて基本クラスに含まれますか?
using System.Windows;
using System.Windows.Controls;
namespace TestDependencyProperty827.DataTypes
{
public partial class DataTypeWholeNumber : BaseDataType
{
public DataTypeWholeNumber()
{
InitializeComponent();
DataContext = this;
//defaults
TheWidth = 200;
}
public string TheLabel
{
get
{
return (string)GetValue(TheLabelProperty);
}
set
{
SetValue(TheLabelProperty, value);
}
}
public static readonly DependencyProperty TheLabelProperty =
DependencyProperty.Register("TheLabel", typeof(string), typeof(BaseDataType),
new FrameworkPropertyMetadata());
public string TheContent
{
get
{
return (string)GetValue(TheContentProperty);
}
set
{
SetValue(TheContentProperty, value);
}
}
public static readonly DependencyProperty TheContentProperty =
DependencyProperty.Register("TheContent", typeof(string), typeof(BaseDataType),
new FrameworkPropertyMetadata());
public int TheWidth
{
get
{
return (int)GetValue(TheWidthProperty);
}
set
{
SetValue(TheWidthProperty, value);
}
}
public static readonly DependencyProperty TheWidthProperty =
DependencyProperty.Register("TheWidth", typeof(int), typeof(DataTypeWholeNumber),
new FrameworkPropertyMetadata());
}
}
Visual継承を使用したWPF回避策:http://svetoslavsavov.blogspot.gr/2009/09/user-control-inheritance-in-wpf.htmlまたは祖先でGUIを明示的に定義する場合はhttp://を参照してください。 support.microsoft.com/kb/957231 –