Wix CustomAction update UI?

后端 未结 2 1638
野的像风
野的像风 2021-01-07 09:45

If I have a managed Wix Custom Action, is there anyway I can update a Control with the type of Text? I see that a progress bar can be updated by using the session.Mess

相关标签:
2条回答
  • 2021-01-07 10:15

    For a text control you can use a property wrapped in brackets: [SOMEPROP]

    Then in your CA you can say session["SOMEPROP"] = "somevalue". Note MSI is wonky about refreshing the UI so you'll pretty much have to transition from one dialog to another to get this to work. In other words, on the next button of the previous dialog call the CA and in the next dialog the text control will display the text.

    0 讨论(0)
  • 2021-01-07 10:24

    I found a solution to get this done without having to transition dialogs in order to get it to update.

    In your custom action, set a property. Below, I set INSTALLFOLDER:

    [CustomAction]
    public static ActionResult SpawnBrowseFolderDialog(Session session)
    {
        session.Log("Started the SpawnBrowseFolderDialog custom action.");
        try
        {
            Thread worker = new Thread(() =>
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog();
                dialog.SelectedPath = session["INSTALLFOLDER"];
                DialogResult result = dialog.ShowDialog();
                session["INSTALLFOLDER"] = dialog.SelectedPath;
            });
            worker.SetApartmentState(ApartmentState.STA);
            worker.Start();
            worker.Join();
        }
        catch (Exception exception)
        {
            session.Log("Exception while trying to spawn the browse folder dialog. {0}", exception.ToString());
        }
        session.Log("Finished the SpawnBrowseFolderDialog custom action.");
        return ActionResult.Success;
    }
    

    In your Product.wxs file, make sure to Publish the property back to the UI in order to get edit boxes to update:

    <Control Id="FolderEdit" Type="PathEdit" X="18" Y="126" Width="252" Height="18" Property="INSTALLFOLDER" Text="{\VSI_MS_Sans_Serif13.0_0_0}MsiPathEdit" TabSkip="no" Sunken="yes" />
    <Control Id="BrowseButton" Type="PushButton" X="276" Y="126" Width="90" Height="18" Text="{\VSI_MS_Sans_Serif13.0_0_0}B&amp;rowse..." TabSkip="no">
        <Publish Event="DoAction" Value="SpawnBrowseFolderDialog"><![CDATA[1]]></Publish>
        <Publish Property="INSTALLFOLDER" Value="[INSTALLFOLDER]"><![CDATA[1]]></Publish>
    </Control>
    

    So in other words, you do the action, then you must publish the property back onto itself to invoke an update in the control.

    0 讨论(0)
提交回复
热议问题