Reputation: 131
I'm Using VB.Net 2012 With WPF
Code
Public Class UserControl1
Inherits Adorner
Sub New(AdornedElement As UIElement)
MyBase.New(AdornedElement)
'Err Found Here
End Sub
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
End Sub
End Class
Error : Base class 'System.Windows.Controls.UserControl' specified for class 'UserControl1' cannot be different from the base class 'System.Windows.Documents.Adorner' of one of its other partial types.
please help
. . . . Edit : Added XAML Code of UserControl
<UserControl x:Class="UserControl1"
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.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text=" This is Child Control " HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Button Grid.Row="1" Content="Close Child Control " HorizontalAlignment="Center" VerticalAlignment="Center" Click="Button_Click"/>
</Grid>
</UserControl>
Edit : Errs. add on Changing UserControl to Adorner
Error 6 Base class 'System.Windows.Controls.UserControl' specified for class 'UserControl1' cannot be different from the base class 'System.Windows.Documents.Adorner' of one of its other partial types. D:\Data - 2012\Temp\WPF Adorners\WPF Adorners\obj\Debug\UserControl1.g.i.vb 42 14 WPF Adorners
Error 1 Cannot add content to an object of type "Adorner". D:\Data - 2012\Temp\WPF Adorners\WPF Adorners\UserControl1.xaml 8 5 WPF Adorners
Error 2 Type 'Adorner' is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter. D:\Data - 2012\Temp\WPF Adorners\WPF Adorners\UserControl1.xaml 1 2 WPF Adorners
Error 3 The type 'Adorner' does not support direct content. D:\Data - 2012\Temp\WPF Adorners\WPF Adorners\UserControl1.xaml 8 5 WPF Adorners
Error 4 Cannot add content to object of type 'System.Windows.Documents.Adorner'. Line 8 Position 6. D:\Data - 2012\Temp\WPF Adorners\WPF Adorners\UserControl1.xaml 8 6 WPF Adorners
Upvotes: 0
Views: 1901
Reputation: 7249
As @Robert has suggested.
You have to change the tag in XAML when you change the inheritance in code behind of the respective XAML file.
You need to change as below in XAML: (see the very first tag and last tags)
<Adorner x:Class="UserControl1"
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.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text=" This is Child Control " HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Button Grid.Row="1" Content="Close Child Control " HorizontalAlignment="Center" VerticalAlignment="Center" Click="Button_Click"/>
</Grid>
</Adorner>
Adorner
is an abstract class so you can't directly use it as is, instead you have to create derived class outside this and then derive the UserControl
from your local Adorner class OR use any existing derived Adorner class.
Check this codeproject article on this topic.
Upvotes: 2
Reputation: 29073
Look at the XAML for your control - it will say the base class is UserControl. Change that to Adorner to be consistent with your VB code.
Upvotes: 1