Extending the WizardPage class

Wizard for WPF Forum

Posted 17 years ago by JB Scoggins
Version: 2.0.0325
Avatar
I would like to extend the WizardPage class into a custom class that can be reused. I am developing a wizard and would like to put all of the logic for each page into seperate classes for better data hiding and cleaner, more readable code. Also, this will allow me to easily reuse each page in other wizards. How can I do this? Also, would this approach be considered the "right way" of doing things?

Thanks for you help!

Comments (17)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi JB,

Sure, that is a perfectly fine way of doing this. What you would do is for each page, create a class that inherits WizardPage (like MyFirstCustomWizardPage). Then you might need to make a Style that has a Setter for the Content of the MyFirstCustomWizardPage type.

After that you simple create an instance of your wizard page in XAML like:

<wizard:Wizard>
  <local:MyFirstCustomWizardPage />
  <local:MySecondCustomWizardPage />
</wizard:Wizard>


Actipro Software Support

Posted 17 years ago by JB Scoggins
Avatar
Thank you for your reply. I would also like to write the xaml that would go with each page, but I am not sure what the root of that xaml file would look like? I tried making it <WizardPage ...>, but the compiler does not recognize that. Do I need to have one of the built in types as the root, and if so, which one.

Thanks
JB
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
That's where I was saying you'd probably need to add a Style for each of your page types to the themes\generic.xaml file for your project, and have the style set the WizardPage.Content property.

So perhaps something like this:

<Style TargetType="local:MyFirstCustomWizardPage">
  <Setter Property="Content">
    <Setter.Value>
      <Button HorizontalAlignment="Center" VerticalAlignment="Center">Test Content</Button>
    </Setter.Value>
  </Setter>
</Style>


Actipro Software Support

Posted 17 years ago by JB Scoggins
Avatar
OK, that sounds good. Thank you for your help. I was hoping that it would be possible to have a xaml and code behind pair for each page that define the class but it does not seem possible to extend a class in code as well as xaml. Thanks agian for your help!
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
In a sense you can do this if you create your C# (or VB) codebehind class and then use merged resources from your generic.xaml file where you merge in one XAML file for each wizard page class type.

Only Windows and UserControls I believe support the sort of pairing I think you are thinking of. Since WizardPages are styled controls you'd have to do it the way posted in the previous posts, however by following the suggestions above you can achieve a separate XAML and codebehind sort of pair.


Actipro Software Support

Posted 16 years ago by michael foster
Avatar
Do you think it's possible to post a sample app on how to do this?

It seems like this would be the desired way of programming. It would make for a busy xaml file to have the layout logic for every wizard page on one form.

thanks,
michael
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Michael,

It looks like we needed to make a couple tweaks for this to work properly based on our testing. These tweaks will be made for the next maintenance release.

What you will be able to do then is have a class def like this:
public class ItemEntryPage : WizardPage {}
Then add a Style like this:

<Style x:Key="{x:Type sample:ItemEntryPage}" TargetType="{x:Type sample:ItemEntryPage}"
    BasedOn="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type wizard:WizardPage},ResourceId=WizardInteriorPageStyle}}">
    
    <Setter Property="Caption" Value="Test caption" />
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <TextBlock>Content here</TextBlock>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>
This all will work in the next maintenance release. Sound like we have it designed how you'd like?


Actipro Software Support

Posted 16 years ago by Matt Swanton
Avatar
Hi Support,

Can you let me know if this fix is in the current release (3.5.0429). I am trying this with the current trial version of the wizard software and I get the following error message when my wizard page is loaded;

Cannot find resource named '{TargetType=ActiproSoftware.Windows.Controls.Wizard.WizardPage ID=WizardInteriorPageStyle}'

Thanks in advance
Matt
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, that all will work as of a while back however since then we made WizardPage's style simpler, with all page types combined yet differentiated using triggers.

So I think that now you can leave out the BasedOn completely and it will work.

However if you do need the BasedOn, try this:
BasedOn="{StaticResource {x:Type wizard:WizardPage}}"


Actipro Software Support

Posted 16 years ago by Matt Swanton
Avatar
Hi,

Thanks for your quick reply.

I no longer get the error message which is great but I think my lack of understanding with styles is causing my next problem.

I'm using the AeroWizard and when I introduce a page that is inherited from WizardPage the caption of the wizard page is no longer rendered in the large blue Aero style, but in a standard small bold style instead (which I think is the non-Aero style).

What can I do to tell the page to use the Aero style?

Thanks
Matt
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Could you possibly make a simple project that shows this happening and email it over? If we need to make a change to fix a problem, we can get it in for the next release. Thanks!


Actipro Software Support

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the sample. The key was that it was an Aero wizard, which has a different style. For v4.0, I've added the ability to do a BasedOn explicitly for this style. So in your sample, you would do this:
<Style x:Key="{x:Type local:TestPage}" TargetType="{x:Type local:TestPage}" 
   BasedOn="{StaticResource {x:Static themes:AeroWizardCommonDictionary.PageStyleKey}}">
This new AeroWizardCommonDictionary.PageStyleKey will be available in the v4.0 release, which should be out in the next several weeks. If you need it earlier and are an existing customer, we could possibly hook you up with a beta version to work with.


Actipro Software Support

Posted 15 years ago by Jeff Pek - Autodesk, Inc.
Avatar
Can you post a sample of doing this more publicly? Or perhaps this is done in the product samples?
Thanks, Jeff
Posted 15 years ago by Jeff Pek - Autodesk, Inc.
Avatar
Followup: I see the sample page in the download. This looks like what I want. So the question is, how exactly was this created? I would have expected to see an entry for WizardPage in the Add New Item dialog, but it's not there.

I was able to create a new page class by modifying some XAML directly; is that really what's required?

Thanks.
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Jeff,

Can you give more details on what exactly you're trying to and where? Sorry but I'm not clear by your messages. Thanks!


Actipro Software Support

Posted 15 years ago by Jeff Pek - Autodesk, Inc.
Avatar
OK. Sorry.
Consider the ItemEntryPage.xaml in the CustomPageClasses folder in the samples.

My question is: how did this get created?

Thanks,
Jeff
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ahh, for that you would have to create a new WPF UserControl then open the XAML and codebehind and change it from UserControl to wizard:WizardPage, etc.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.