Question

I created a project wizard for my template. With this wizard the user can fill in a couple of thing like the app name, and then create the app. The problem is that the wizard is launched, but then the project is created immediately instead of after finishing the wizard. This means that replacements aren't taking place.

I have this form (heavily simplified):

<Window x:Class="PartyTemplateWizard.Form"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="340" d:DesignWidth="750">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TextBlock Text="Name" Grid.Column="0" />

        <TextBox x:Name="Name" Grid.Column="1" Text="{Binding Path=dummyproperty, FallbackValue='Naam'}" />

        <Button Content="Ok" Grid.Column="1" Grid.Row="1" />
    </Grid>
</Window>

With a wizard:

public class Wizard : IWizard
{
    private readonly Form _form = new Form();

    public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
    {
        try
        {
            _form.Show();

            string name = _form.Name.Text;

            if (!string.IsNullOrEmpty(name)) replacementsDictionary.Add("$appname$", name);
        }
        catch (Exception e)
        {
        }
    }

    public bool ShouldAddProjectItem(string filePath)
    {
        return true;
    }

    public void RunFinished()
    {
    }

    public void BeforeOpeningFile(ProjectItem projectItem)
    {
    }

    public void ProjectItemFinishedGenerating(ProjectItem projectItem)
    {
    }

    public void ProjectFinishedGenerating(Project project)
    {
    }
}

And I bound this to my template with this bit of code:

<WizardExtension>
  <Assembly>PartyTemplateWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=6c4fd97fa2ac3b4f</Assembly>
  <FullClassName>PartyTemplateWizard.Wizard</FullClassName>
</WizardExtension>

Full code available on github: https://github.com/Avalaxy/PartyTemplateWizard

Does anyone know why the project is being created before the wizard finished succesfully (even though that isn't possible since there is no event handler on the Ok button yet)?

Was it helpful?

Solution

Try using _form.ShowDialog(); instead so that your main thread is blocked. At the moment it seems that the RunStarted method executes without blocking so your customised form isn't used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top