Di seguito WPF UserControl chiamato DataTypeWholeNumber che funziona.In che modo un UserControl WPF eredita un UserControl WPF?
Ora voglio fare un controllo utente chiamato DataTypeDateTime e DataTypeEmail, ecc
Molte delle proprietà di dipendenza saranno condivisi da tutti questi controlli, e quindi voglio mettere loro metodi comuni in un BaseDataType e ognuno di questi UserControls eredita da questo tipo di base.
Tuttavia, quando lo faccio, ottengo l'errore : Dichiarazione parziale non può avere diverse classi di base.
Così come posso implementare eredità con controlli utente in modo condiviso la funzionalità è tutta nella classe di base?
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());
}
}
per la soluzione WPF con ereditarietà visiva: http://svetoslavsavov.blogspot.gr/2009/09/user-control-inheritance-in-wpf.html o per la definizione esplicita della GUI nell'antenato, consultare http: // support.microsoft.com/kb/957231 –