How can a WPF UserControl inherit a WPF UserControl?

前端 未结 5 1385
独厮守ぢ
独厮守ぢ 2020-11-28 21:46

The following WPF UserControl called DataTypeWholeNumber which works.

Now I want to make a UserControl called DataTypeDateTime and

5条回答
  •  醉梦人生
    2020-11-28 22:31

    Ensure that you have changed the first tag in the xaml to also inherit from your new basetype

    So

    
    

    becomes

    
    

    So, to summarise the complete answer including the extra details from the comments below:

    • The base class should not include a xaml file. Define it in a single (non-partial) cs file and define it to inherit directly from Usercontrol.
    • Ensure that the subclass inherits from the base class both in the cs code-behind file and in the first tag of the xaml (as shown above).

提交回复
热议问题