Wix Interactions with Conditions, Properties & Custom Actions

放肆的年华 提交于 2019-11-27 00:45:05

http://www.mail-archive.com/wix-users@lists.sourceforge.net/msg05097.html gives an solution to republish the properties that were changed in the custom action immediately after it.

Here is an example of how I have gotten it to work in my code:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <Binary Id="ConnectionStringExtension.dll" SourceFile="$(var.ConnectionStringExtension.TargetDir)$(var.ConnectionStringExtension.TargetName).CA.dll" />
        <CustomAction Id="MyCustomAction" BinaryKey="ConnectionStringExtension.dll" DllEntry="VerifyConnectionString" Execute="immediate"  />

        <UI>
            <Dialog Id="ConnectionStringDlg" Width="370" Height="270" Title="Database Settings - [ProductName]" NoMinimize="yes">
                <Control Id="ConnectionStringLabel" Type="Text" X="45" Y="73" Width="100" Height="15" TabSkip="no" Text="&amp;Connection String:" />
                <Control Id="ConnectionStringEdit" Type="Edit" X="45" Y="95" Width="220" Height="15" Property="CONNECTION_STRING" Text="{200}" />
                <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="&amp;Back">
                </Control>
                <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&amp;Next">
                    <Condition Action="enable"><![CDATA[CONNECTION_STRING <> "" AND CONNECTION_STRING_VALID = "1"]]></Condition>
                    <Condition Action="disable"><![CDATA[CONNECTION_STRING = "" OR CONNECTION_STRING_VALID = "0"]]></Condition>
                </Control>
                <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">
                    <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
                </Control>
                <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="WixUI_Bmp_Banner" />
                <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes">
                    <Text>Please enter database configuration</Text>
                </Control>
                <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
                <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes">
                    <Text>{\WixUI_Font_Title}Database Settings</Text>
                </Control>
                <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
              <Control Id="VerifyButton" Type="PushButton"  Width="56" Height="16" X="45" Y="118" Text="Verify">
                <Publish Event="DoAction" Value="MyCustomAction">1</Publish>
                <Publish Property="TEMP_VERIFIED" Value="[CONNECTION_STRING_VALID]">1</Publish>
                <Publish Property="CONNECTION_STRING_VALID" Value="[TEMP_VERIFIED]" />
              </Control>
            </Dialog>
        </UI>
    </Fragment>
</Wix>

The CustomAction sets the value of CONNECTION_STRING_VALID to either 1 or 0 depending if it is valid or not and I have defined elsewhere that by default its value is 0

<Property Id="CONNECTION_STRING_VALID" Value="0" />

Now when I click my verify button if the string is valid the next button is enabled

This is a well-known limitation of Windows Installer. The state of the dialog doesn't change until you refresh it in any other way, for instance, moving back and forward, as you correctly mentioned.

The workaround here is to have two identical dialogs, DialogA and DialogB. The PerformValidation button on DialogA will perform validation as it does right now and call DialogB (as NewDialog). The same way, the PerformValidation button on DialogB will also perform validation and call DialogA. Thus, you'll have the dialogs to be loaded each time you run validation and button state will be correctly displayed. The user won't suspect anything, because he/she will only see the same dialog. :-)

The idea is described better in detail here. It is called "twin dialogs".

Hope this helps.

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