Reputation: 81
I am developing a Silverlight gadget for Windows widget. When I add another page in my widget then I found this error. I found in Stack Overflow same question, but it was not for widget.
My sample code is here XAML code
<navigation:Page x:Class="SilverlightGadgetDocked.Test"
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"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="359" d:DesignHeight="225"
Title="Test Page">
<Grid x:Name="LayoutRoot">
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="182,103,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</navigation:Page>
and cs code is here,
public partial class Test:UserControl
{
public Test()
{
MessageBox.Show("af");
InitializeComponent();
}
// Executes when the user navigates to this page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void button1_Click(object sender, RoutedEventArgs e)
{
}
}
Upvotes: 3
Views: 3968
Reputation: 5659
Your code behind specified a base class of UserControl
but your XAML file specifies a base class of Page
(the root node of the document corresponds to the base class of the type).
Change
public partial class Test:UserControl
To
public partial class Test
And all will be well. It's worth noting that you don't actually have to specify base classes on all parts of a partial class. Since the base class is set in the XAML file, there's no need to specify it again on the class in the code behind (but, if you did, it'd have to match the type specified in the XAML).
Upvotes: 3