locked
Deriving from Custom UserControl RRS feed

  • Question

  • Hi

    Is it possible to do the following in WPF:

    BaseUserControl.xaml

       <UserControl x:Name="BaseUserControl"></UserControl>

    BaseUserControl.xaml.cs

       public class BaseUserControl : UserControl {}

    Now derive another control from this control:

    InheritedControl.xaml

    <local:BaseUserControl x:Name= "InheritedControl"></local:BaseUserControl>

    InheritedControl.xaml.cs

    public class InheritedControl: BaseUserControl {}

    Thanks

    Tuesday, October 29, 2013 9:29 AM

Answers

All replies

  • Hi

    Here you go: http://stackoverflow.com/questions/9020335/derive-user-control-from-custom-user-control-base-class


    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you.

    • Marked as answer by thisissuneel Tuesday, November 5, 2013 5:06 PM
    Tuesday, October 29, 2013 9:35 AM
  • It is possible:

    Make sure your derivation turns from this:

    <UserControl x:Class="MyProject..." xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" >

    ......

    Into this:

    <local:BaseUserControl x:Class="MyProject..." xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" >

    ...

    You might want to check this link out:

    http://csharpsimplified.wordpress.com/2011/09/21/subclassing-wpf-user-control/

    Tuesday, October 29, 2013 9:38 AM