1

I have a class called BIFUserControl which inherits from UserControl class. Now I am designing a new user control called BIFText which inherits from BIFUserControl class. So, I changed the XAML file called BIFText.xaml as follows :

<base:BIFUserControl 
              xmlns:base="clr-namespace:BaseInputFramework.BaseWidgets;assembly=BaseInputFramework"
              x:Class="BIFWidgetLibrary.Text.BIFText"
              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" 

              xmlns:mp="clr-namespace:Microsoft.Multipoint.Sdk.Controls;assembly=Microsoft.Multipoint.Sdk.Controls"
              xmlns:utils="clr-namespace:BaseInputFramework.BaseWidgets.Utils;assembly=BaseInputFramework"

              mc:Ignorable="d" 
              d:DesignHeight="150" d:DesignWidth="150">
     <Grid>


     </Grid> </base:BIFUserControl>

And then I changed my BIFText.xaml.cs file as follows:

 namespace BIFWidgetLibrary.Text {
     public partial class BIFText : BIFUserControl
     {
         public BIFText()
         {
             InitializeComponent();
         }
     } }

But now when I try to build the project, I get the following error message : 'BaseInputFramework.BaseWidgets.BIFUserControl' cannot be the root of a XAML file because it was defined using XAML. Line 2 Position 14.

Can someone please help me with this error. Thanks in advance.

H.B.
  • 166,899
  • 29
  • 327
  • 400
Himanshu Verma
  • 257
  • 1
  • 3
  • 10

2 Answers2

4

Error says itself that BaseInputFramework.BaseWidgets.BIFUserControl cannot be root of a XAML file since it is defined using XAML. Only elements which are not defined using XAML file can only be root element. Refer to these links - Cannot define root element and Inheriting from UserControl

Community
  • 1
  • 1
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
  • 1
    Yes you are write, I quickly made a new Base UserControl class without a XAML file. And after that the above code works for me. Thanks ! – Himanshu Verma Sep 08 '12 at 18:41
1

UserControls work by setting the Content to what you define in XAML, this might be the reason why you cannot inherit like that: The base class' content would be overwritten.

If you don't mind completely replacing the content you might as well use a custom control and define a Template instead.

H.B.
  • 166,899
  • 29
  • 327
  • 400