Create base page for Silverlight Page

If you would like to create a base page with common functionality – create your own base page and derive each new page from the base class.

Create BasePage.cs

namespace MyApp.Views
{
    public class BasePage:Page
    {
    }
}

Derive the real page from the BasePage.cs

namespace MyApp.Views
{
    public partial class NewPage: BasePage
    {
    }
}

Now if you compile the project you will get the following error:
Partial declarations of ‘MyApp.Views.NewPage’ must not specify different base classes

Here you should do two more steps:

Change the Xaml accodringly:

from:

namespace MyApp.Views
<navigation:Page x:Class="MyApp.Views.EditArticle"

           .../>
</navigation:Page>

to:

<local:BasePage x:Class="MyApp.Views.NewPage"
           xmlns:local="clr-namespace:MyApp.Views"
           .../>

</local:BasePage>

And the last important thing – Add reference to AssemblyInfo.cs

  [assembly: XmlnsDefinition("http://schemas.microsoft.com/client/2007", "MyApp.Views")]

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackbacks and Pingbacks: