Wix CustomAction update UI?

落爺英雄遲暮 提交于 2019-12-04 19:48:08

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!