相关疑难解决方法(0)

WPF UserControl如何继承WPF UserControl?

以下WPF UserControl称为DataTypeWholeNumber,它可以正常工作.

现在我想创建一个名为DataTypeDateTimeDataTypeEmail等的UserControl .

许多依赖属性将由所有这些控件共享,因此我想将它们的公共方法放入BaseDataType中,并使每个UserControl都继承自此基类型.

但是,当我这样做时,我得到错误:部分声明可能没有不同的基类.

那么如何使用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);
            } …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml user-controls

87
推荐指数
1
解决办法
6万
查看次数

标签 统计

c# ×1

user-controls ×1

wpf ×1

xaml ×1