Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can a WPF UserControl inherit a WPF UserControl?
    text
    copied!<p>The following WPF UserControl called <strong>DataTypeWholeNumber</strong> which works.</p> <p>Now I want to make a UserControl called <strong>DataTypeDateTime</strong> and <strong>DataTypeEmail</strong>, etc.</p> <p>Many of the Dependency Properties will be shared by all these controls and therefore I want to put <strong>their common methods into a BaseDataType</strong> and have each of these UserControls inherit from this base type.</p> <p>However, when I do that, I get the <strong><em>error: Partial Declaration may not have different base classes</em></strong>.</p> <p>So how can I implement inheritance with UserControls so shared functionality is all in the base class?</p> <pre><code>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()); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload