Wpf - Inheriting UserControl

I have a problem with control inheritance in WPF. I created a UserControl named BaseUserControl. I want this control to be a basic control for other WPF user controllers. So I wrote another UserControl called FirstComponent. In the next step, I changed this code

FirstComponent : UserControl

to that

FirstComponent : BaseControl

However, during compilation I get this error

Partial declarations of 'controlinheritance.componenets.FirstComponent' must not specify different base classes 

What do I need to do to get FirstComponent from BaseControl?

EDIT Thanks to the response abhishek, I managed to inherit the controls. I have one more question. In the base class, I specified the property public Grid _MainGrid {get; set; }. Now I want an instance of this mesh to be created in my derived class. So I used this Howerver code. I get an error. The property "_MainGrid" does not matter. Line 8 Position 36.

+5
source share
3 answers

Have you seen my full article about this?

http://www.dotnetfunda.com/articles/article832-define-base-class-for-window--usercontrol-.aspx

Hope this helps you with this.

, , , . , WPF baseWindow , . , . XAML, , - Window, .

, , .

, :

<local:BaseWindow Class="BaseWindowSample.Window1" 
                  Name="winImp" 
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                  x="http://schemas.microsoft.com/winfx/2006/xaml" 
                  xmlns:local="clr-namespace:BaseWindowSample" 
                  Title="Window1">
...
</local:BaseWindow>

, , . , BaseWindow BaseWindow , , : BaseWindow

+5

, , , - , .

,

public Grid MainGrid 
{ 
   get 
   { 
      return base.MainGrid; 
   } 

   set 
   { 
      base.MainGrid = value; 
   } 
}

, . , , . ...

public Grid MainGrid
{
    get
    {
        return BaseControl.MainGrid;
    }

    set
    {
        BaseControl.MainGrid = value;
    }
}
0

Usercontrol XAML.cs

 FirstComponent : BaseControl

XAML

 <Base:BaseControl x:Class="FirstComponent"
             xmlns:Base="clr-namespace:MyApplication.Base"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>


    </Grid>
</Base:BaseControl>
0

All Articles