Answered by:
PageFunction Base Class

Question
-
Hello,
Recently, I put together a quick prototype for a wizard (with your help). Now I'm looking at it and it feels like that I copy pasted a lot of code. So now, I would like to create a class hierarchy for my wizard pages (developed using page functions). But whatever I try I get a compiler error :(Is it possible to have a concrete pure PageFunction class to act the base class for several other page functions.
Something like this:Public Class BaseWizardPageFunction : System.Windows.Navigation.PageFunction<String>
{
public virtual void Method1(){...}
}Then have a partial page function with accompanying XAML code such as:
Public Partial Class WizardStartPage : BaseWizardPageFunction
{
....
}<PageFunction
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="WindowsApplication.MyPageFunction1"
x:TypeArguments="sys:String"
Title="PageFunction1">I get a compiler error:
Partial declarations of 'WindowsApplication4.PageFunction1' must not specify different base classesAnd if I remove the x:TypeArguments attribute I get a compiler error:
The tag 'PageFunction' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.Thanks
Houman
P.S. this was encouraging but it doesn't really address the problem:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=374297&SiteID=1
Friday, September 15, 2006 3:54 AM
Answers
-
You were pretty close to the right solution. The compiler rightly complains about the differing base classes. In general, the way XAML compilation works is that your code-behind is merged with the code the compiler generates. The two parts have to be partial classes derived from the same base. The base the compiler uses is the root of the XAML tree. So, to fix your example:
<my:BaseWizardPageFunction
xmlns:my="clr-namespace:WindowsApplication4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="WindowsApplication.MyPageFunction1"
Title="PageFunction1">(Note, no TypeArguments.)
Friday, September 15, 2006 5:08 PM
All replies
-
You were pretty close to the right solution. The compiler rightly complains about the differing base classes. In general, the way XAML compilation works is that your code-behind is merged with the code the compiler generates. The two parts have to be partial classes derived from the same base. The base the compiler uses is the root of the XAML tree. So, to fix your example:
<my:BaseWizardPageFunction
xmlns:my="clr-namespace:WindowsApplication4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="WindowsApplication.MyPageFunction1"
Title="PageFunction1">(Note, no TypeArguments.)
Friday, September 15, 2006 5:08 PM -
That is Excellent...Thanks so much!
Is there a place I can learn more about how the xaml compilation work...
Regards,
Houman
Saturday, September 16, 2006 3:12 AM -
See the Build and Deploy section of the SDK for WPF. Specifically the article on the WPF Build System. Enjoy!Tuesday, September 19, 2006 12:19 AM
-
Thanks!Tuesday, September 19, 2006 2:36 AM