在运行时禁用控件的可能方法?

时间:2013-09-03 08:49:48

标签: wix

有没有办法在我执行某些操作(如检查数据库可用性)时禁用UI控件?现在就是这样:

<Control Id="Next" Type="PushButton">
    <Publish Event="DoAction" Value="CheckDBConnection" Order="3">
        <![CDATA[SQL_SERVER <> "" AND SQL_USER <> "" AND SQL_PASSWORD <> ""]]>
    </Publish>
    <Publish Event="DoAction" Value="Confirm_OverwriteDatabase" Order="2"/>
    <Publish Event="NewDialog" Value="VerifyReadyDlg" Order="1"/>
</Control>

执行CheckDBConnection时,所有控件都处于活动状态,但不执行任何操作。在执行后台操作时禁用它们会更准确。

2 个答案:

答案 0 :(得分:0)

根据所需的属性,使用带有启用\禁用操作的条件:

<Control Id="{Id}" Type="{Type}">
     <Condition Action="enable" ><![CDATA[SOMEPROPERTY = SomeValue]]></Condition>
     <Condition Action="disable"><![CDATA[SOMEPROPERTY <> SomeValue]]></Condition>
</Control>

答案 1 :(得分:0)

感谢@ vitaliy-zadorozhnyy,我能够想出一个我自己也不了解的奇怪代码。但它确实有效。

...
...

<Property Id="DBCHECK_INPROGRESS" Value="0" />
<Property Id="DBCHECK_NOTINPROGRESS" Value="0" />

...
...

<Control Id="{Id}" Type="{Type}">
    <Condition Action="enable"><![CDATA[DBCHECK_INPROGRESS <> 1]]></Condition>
    <Condition Action="disable"><![CDATA[DBCHECK_INPROGRESS = 1]]></Condition>
</Control>

{insert those conditions for any control you want to disable during action}

...
...


<Control Id="Next" Type="PushButton">
    <Condition Action="enable"><![CDATA[DBCHECK_INPROGRESS <> 1]]></Condition>
    <Condition Action="disable"><![CDATA[DBCHECK_INPROGRESS = 1]]></Condition>

    <Publish Event="DoAction" Value="SetInProgress">1</Publish>
    <Publish Property="TEMP_INPROGRESS" Value="[DBCHECK_INPROGRESS]">1</Publish>
    <Publish Property="DBCHECK_INPROGRESS" Value="[TEMP_INPROGRESS]" />

    <Publish Event="DoAction" Value="CheckDBConnection"/>

    <Publish Event="DoAction" Value="SetNotInProgress">1</Publish>
    <Publish Property="TEMP_NOTINPROGRESS" Value="[DBCHECK_NOTINPROGRESS]">1</Publish>
    <Publish Property="DBCHECK_NOTINPROGRESS" Value="[TEMP_NOTINPROGRESS]" />

    {other events}

</Control>

和自定义操作(JScript)很简单:

function SetInProgress_CA() {
    Session.Property("DBCHECK_INPROGRESS") = "1";
}
function SetNotInProgress_CA() {
    Session.Property("DBCHECK_INPROGRESS") = "0";
}