<p>I have decided that all my WPF pages need to register a routed event.  Rather than include</p>

<pre><code>public static readonly RoutedEvent MyEvent= EventManager.RegisterRoutedEvent("MyEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BasePage));
</code></pre>

<p>on every page, I decided to create a base page (named BasePage).  I put the above line of code in my base page and then changed a few of my other pages to derive from BasePage.  I can't get past this error:</p>

<blockquote>
  <p>Error 12  'CTS.iDocV7.BasePage' cannot
  be the root of a XAML file because it
  was defined using XAML. Line 1
  Position
  22.   C:\Work\iDoc7\CTS.iDocV7\UI\Quality\QualityControlQueuePage.xaml    1   22  CTS.iDocV7</p>
</blockquote>

<p>Does anyone know how to best create a base page when I can put events, properties, methods, etc that I want to be able to use from any wpf page?</p>

[{'answer_id': 40330, 'author': 'Daren Thomas', 'author_id': 2260, 'author_profile': 'https://Stackoverflow.com/users/2260', 'pm_score': 2, 'selected': False, 'text': "<p>I'm not sure on this one, but looking at your error, I would try to define the base class with just c# (.cs) code - do not create one with XAML, just a standard .cs file that extends the WPF Page class.</p>\n"}, {'answer_id': 40868, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 6, 'selected': True, 'text': '<p>Here\'s how I\'ve done this in my current project.</p>\n\n<p>First I\'ve defined a class (as @Daren Thomas said - just a plain old C# class, no associated XAML file), like this (and yes, this is a real class - best not to ask):</p>\n\n<pre><code>public class PigFinderPage : Page\n{\n    /* add custom events and properties here */\n}\n</code></pre>\n\n<p>Then I create a new Page and change its XAML declaration to this:</p>\n\n<pre><code>&lt;my:PigFinderPage x:Class="Qaf.PigFM.WindowsClient.PenSearchPage"\n    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\n    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\n    xmlns:my="clr-namespace:Qaf.PigFM.WindowsClient"\n    /&gt;\n</code></pre>\n\n<p>So I declare it as a PigFinderPage in the "my" namespace. Any page-wide resources you need have to be declared using a similar syntax:</p>\n\n<pre><code>&lt;my:PigFinderPage.Resources&gt;\n    &lt;!-- your resources go here --&gt;\n&lt;/my:PigFinderPage.Resources&gt;\n</code></pre>\n\n<p>Lastly, switch to the code-behind for this new page, and change its class declaration so that it derives from your custom class rather than directly from Page, like this:</p>\n\n<pre><code>public partial class EarmarkSearchPage : PigFinderPage\n</code></pre>\n\n<p>Remember to keep it as a partial class.</p>\n\n<p>That\'s working a treat for me - I can define a bunch of custom properties and events back in "PigFinderPage" and use them in all the descendants.</p>\n'}, {'answer_id': 40918, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 2, 'selected': False, 'text': '<p>Also, have a look at <a href="http://msdn.microsoft.com/en-us/library/bb613550.aspx" rel="nofollow noreferrer">Attached Events</a> and see if you can attach your event to every Page in your app. Might be easier than a custom intermediary class.</p>\n'}, {'answer_id': 18911021, 'author': 'Farzad J', 'author_id': 199769, 'author_profile': 'https://Stackoverflow.com/users/199769', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://weblogs.asp.net/psheriff/archive/2009/11/02/creating-a-base-window-class-in-wpf.aspx" rel="nofollow">Here</a> is a tutorial too !\nit\'s pretty simple and easy.</p>\n'}, {'answer_id': 32494996, 'author': 'Myosotis', 'author_id': 1756640, 'author_profile': 'https://Stackoverflow.com/users/1756640', 'pm_score': 1, 'selected': False, 'text': '<p>Little update : I just tried to do it, and it didn\'t work. He is what I changed to solve the problem:</p>\n\n<p>1.In many forums, you will read that the sub pages must inherit from a simple cs class, without XAML. Though it works. I do inherit from a normal XAML page without any problem.</p>\n\n<p>2.I replaced the following code :</p>\n\n<pre><code>&lt;my:PigFinderPage x:Class="Qaf.PigFM.WindowsClient.PenSearchPage"\nxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\nxmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\nxmlns:my="clr-namespace:Qaf.PigFM.WindowsClient"\n/&gt;\n</code></pre>\n\n<p>with</p>\n\n<pre><code>&lt;my:PigFinderPage x:Class="Qaf.PigFM.WindowsClient.PenSearchPage"\nxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\nxmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\nxmlns:my="using:Qaf.PigFM.WindowsClient"\n/&gt;\n</code></pre>\n\n<p>because when I had "clr-namespace" instead of "using", the Intellisense could recognize PigFinderPage, but not the compiler.</p>\n'}]
['https://Stackoverflow.com/questions/39843', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3047/']