Dynamically creating Wizard Pages in C#?

Wizard for WPF Forum

Posted 11 years ago by George Mills
Avatar
I'm pretty sure this can be done but does anyone have some sample code for dynamically creating the Wizard Pages rather than all decalritively in XAML.

What I want to do is query and XML file as a "Template" for the Wizard. Basically ask the user a bunch of questions based on content of the XML file.

I'm new at WPF and this is little overwhelming to grasp.

Sample project from actipro would be ideal.

Thanks.

Note: The "Pages" will be limited to several styles, so "Templates" of the Pages could be in XAML. And the C# code would tweak user selections to go to these pages whcih would get also tweaked before being presented each time.

Comments (2)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi George,

We don't really have any samples on this but if you follow general WPF samples on programmatic control creation, it's all the same thing. To add a page to a wizard, you do something like:
WizardPage page = new WizardPage();
page.Title = "My title";
wizard.Items.Add(page);
WizardPage is a ContentControl so you can populate its interior by setting the Content property to anything. This is generally a Panel-based control with more child controls in it.

I believe the MSDN on Microsoft's web site has a lot of info on programmatically working with panels, controls and content. All that information would apply here.

Also of note, we have a CustomPageClasses QuickStart in the Sample Browser that shows you how to make a template for a page in XAML and the data bind the page and have that populate the template. The data binding is in code-behind. Perhaps that sample will help you too.


Actipro Software Support

Posted 11 years ago by George Mills
Avatar
You are right.

Here is a snippet of code in case anyone is interested. Works very nice. Needs a whole bunch more cosmetics but the idea works nice.

private void GenerateWizardPages(Uri filePath)
{
XmlReaderSettings readerSettings = XmlUtils.CreateValidatingSettings();
XmlReader reader = XmlReader.Create(filePath.LocalPath, readerSettings);
template = (RootMethodTemplate)new XmlSerializer(typeof(RootMethodTemplate)).Deserialize(reader);

WizardPage page = new WizardPage();
browseTemplatePage.NextPage = page;

WizardPage lastPage = page;

foreach (PromptValue prompt in template.PromptValues)
{
WizardPage nextpage = new WizardPage();
page.NextPage = nextpage;

StackPanel sp = new StackPanel();

page.Content = sp;
Label label = new Label();
label.Content = prompt.name;

TextBox tb = new TextBox();
tb.Tag = prompt;
tb.LostFocus += new RoutedEventHandler(tb_LostFocus);

sp.Children.Add(label);
sp.Children.Add(tb);

page.Name = "ParameterPage_" + pageCount++.ToString();// prompt.name;// "path2Page";// "ParameterPage." + prompt.name;

wizard.Items.Add(page);

lastPage = page;
page = nextpage;
}

lastPage.NextPage = finishPage;
}

void tb_LostFocus(object sender, RoutedEventArgs e)
{
lastValue = ((TextBox)sender).Text;
lastPrompt = (PromptValue) ((TextBox)sender).Tag;
}
The latest build of this product (v2019.1 build 0683) 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.