Silverlight UserControl Inheritance
My current project requires several silverlight user controls. Most of the control has some common functionalities. I decided to create a base class inherits from UserControl. Then add the base class to my user controls.
The issue arise when I tried to build the solution, I started getting the bellow compile time error.
Error 1 Partial declarations of ‘ImageEditor.Controls.CallOut’ must not specify different base classes F:\XXXX\obj\Debug\Controls\CallOut.g.i.cs 36 26 <ProjectName>
The solution to this issue is, in XAML change <UserControl …..</UserControl> to the name of your base class. See the eg. below
<UI:ControlBase x:Class="ImageEditor.Controls.CallOut" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:UI="clr-namespace:ImageEditor.Controls" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <Border x:Name="rectBorder" Grid.Row="0" BorderBrush="Black" BorderThickness="3" CornerRadius="5"> <TextBox x:Name="txtAnnotate" AcceptsReturn="True"></TextBox> </Border> </Grid> </UI:ControlBase >
In the above xaml I replace UserControl with my base class. In order to use my base class I should refer my namespace using xmlns:UI=”clr-…..”. You can see the changes by looking at the sections underlined.
Leave a Reply