El siguiente WPF UserControl llamó al DataTypeWholeNumber que funciona.¿Cómo puede un UserControl de WPF heredar un UserControl de WPF?
Ahora quiero hacer un control de usuario llama DataTypeDateTime y DataTypeEmail, etc.
Muchas de las propiedades de dependencia será compartida por todos estos controles y por lo tanto quiero poner sus métodos comunes en una BaseDataType y hacer que cada uno de estos UserControls herede de este tipo base.
Sin embargo, cuando lo hago, me sale el error : Declaración parcial no puede tener diferentes clases de base.
Entonces, ¿cómo puedo implementar la herencia con UserControls para que la funcionalidad compartida esté en la clase 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());
}
}
para la solución de WPF con herencia visual, consulte: http://svetoslavsavov.blogspot.gr/2009/09/user-control-inheritance-in-wpf.html o para definir explícitamente la GUI en el antecesor, vea http: // support.microsoft.com/kb/957231 –