Wix CustomAction update UI?

2019-04-16 03:52发布

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.Message with InstallMessage.Progress, but I do not see a way for updating other UI.

2条回答
我命由我不由天
2楼-- · 2019-04-16 04:11

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.

查看更多
Root(大扎)
3楼-- · 2019-04-16 04:28

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.

查看更多
登录 后发表回答