WPF UserControl sau đây được gọi là DataTypeWholeNumber hoạt động.Làm thế nào để một UserFrol WPF kế thừa một UserFrol WPF?
Bây giờ tôi muốn thực hiện một UserControl gọi DataTypeDateTime và DataTypeEmail vv
Nhiều người trong số Properties phụ thuộc sẽ được chia sẻ bởi tất cả các điều khiển và do đó tôi muốn đặt phương pháp phổ biến của họ vào một BaseDataType và có mỗi UserControl này kế thừa từ loại cơ sở này.
Tuy nhiên, khi tôi làm điều đó, tôi nhận được lỗi : Tuyên bố một phần có thể không có các lớp cơ sở khác nhau.
Vậy làm thế nào tôi có thể thực hiện kế thừa với UserControls để chức năng chia sẻ là tất cả trong lớp cơ sở?
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());
}
}
cho cách giải quyết WPF với kế thừa Visual xem: http://svetoslavsavov.blogspot.gr/2009/09/user-control-inheritance-in-wpf.html hoặc để xác định rõ ràng GUI trong tổ tiên xem http: // support.microsoft.com/kb/957231 –