【问题标题】:WIX Popup dialogWIX 弹出对话框
【发布时间】:2013-10-28 08:45:14
【问题描述】:

我有两个自定义对话框 - dlg1 和 dlg2。在用户单击 dlg1 上的 NEXT 后,应显示另一个带有一些文本和 OK 按钮的自定义弹出对话框。用户在此弹出窗口上单击“确定”后,应出现 dlg2。我尝试了很多东西,但最好的只是在 dlg1 和 OK-popup 之上显示 dlg2。

【问题讨论】:

    标签: wix wix3.7


    【解决方案1】:

    您必须创建一个模式对话框,将用户从第一个对话框传递到第二个对话框。实际上,模态对话框用于显示消息,然后将焦点返回到调用模态对话框的对话框。我不知道您是否违反了任何安装程序规则,如果您没有将焦点返回到调用对话框但它似乎有效:

    dlg1 的代码:

    <UI>
      <Dialog Id="dlg1" ...>
        <Control Id="firstText" Type="Text" X="10" Y="10" Width="200" Height="17" Text="First Dialog calls Modal Dialog." />
        <Control Id="PopupButton" Type="PushButton" Text="Show Popup" Height="17" Width="56" X="100" Y="243" Default="yes">
          <Publish Event="SpawnDialog" Value="PopupDlg" />
        </Control>
      </Dialog>
    </UI>
    

    PopupDlg 的代码:

    <UI>
      <Dialog Id="PopupDlg" ...>
        <Control Id="OkButton" Type="PushButton" Text="{\Tahoma_Bold}OK" Height="17" Width="56" X="200" Y="175">
          <Publish Event="NewDialog" Value="dlg2" />
        </Control>
      </Dialog>
    </UI>
    

    dlg2 的代码:

    <UI>
      <Dialog id="dlg2" ...>
        <Control Id="secondText" Type="Text" X="10" Y="10" Width="200" Height="17" Text="Now proceed." />
        <Control Id="CancelButton" Type="PushButton" Text="Cancel" Height="17" Width="56" X="180" Y="243">
          <Publish Event="EndDialog" Value="Exit" />
        </Control>
      </Dialog>
    </UI>
    

    更新 实施上述解决方案会产生一些问题。虽然有一种解决方法,但它会降低您的代码的可读性。在发布一些代码之前,让我先描述一下解决方法背后的概念。基本上你将只有两个对话框:一个触发弹出窗口和弹出窗口本身。如上所述,在弹出窗口中,您不会打开新窗口,而是将焦点返回到调用对话框。此外,您还可以更改属性的状态。调用对话框会根据模式对话框设置的属性进行更新。

    为实现这一目标,您必须为调用对话框中的每个状态添加控件,一个用于已设置属性的情况,一个用于未设置属性的情况。

    调用Dialog的代码:

    <UI>
      <Dialog Id="callingDialog" ...>
        <Control Id="BeforePopup" Type="Text" X="10" Y="10" Width="200" Height="17" Text="Here is some text." Hidden="yes">
          <Condition Action="show"><![CDATA[NOT PROP_SET_BY_MODAL_DLG]]></Condition>
          <Condition Action="hide"><![CDATA[PROP_SET_BY_MODAL_DLG]]></Condition>
        </Control>
        <Control Id="AfterPopup" Type="Text" X="10" Y="10" Width="200" Height="17" Text="Popup was shown." Hidden="yes">
          <Condition Action="show"><![CDATA[PROP_SET_BY_MODAL_DLG]]></Condition>
          <Condition Action="hide"><![CDATA[NOT PROP_SET_BY_MODAL_DLG]]></Condition>
        </Control>
        <Control Id="PopupButton" Type="PushButton" Text="Show Popup" Height="17" Width="56" X="100" Y="243" Default="yes">
          <Publish Event="SpawnDialog" Value="PopupDlg" />
        </Control>
      </Dialog>
    </UI>
    

    PopupDlg 的代码:

    <UI>
      <Dialog Id="PopupDlg" ...>
        <Control Id="OkButton" Type="PushButton" Text="OK" Height="17" Width="56" X="200" Y="175">
          <Publish Property="PROP_SET_BY_MODAL_DLG" Value="1" Order="1">1</Publish>
          <Publish Event="EndDialog" Value="Return" Order="2">1</Publish>
        </Control>
      </Dialog>
    </UI>
    

    【讨论】:

    • 我试过了。在您移动 dlg2 窗口之前,一切看起来都很好——您将看到打开的 dlg1 和 PopupDlg。有没有办法关闭它们?
    • 啊,所以我们确实违反了一些规则。您可以更改 PopupDlg 中的 Publish 元素,请参阅我更新的答案。
    【解决方案2】:

    为此找到了另一种解决方案。它是从自定义操作中使用 WinForms 对话框。

    当用户单击 NEXT 按钮时调用自定义操作:

     <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)">
           <Publish Event="DoAction" Value="SomeAction">1</Publish>
     </Control>
    

    在此自定义操作中,您可以调用 WinForm 对话框。并且不要忘记设置静默安装模式的检查以确保在静默安装期间不会显示对话框:

    [CustomAction]
    public static ActionResult SomeAction(Session session)
    {       
       if(Int32.Parse(session["UILevel"]) > 3)
       {   
          var result = MessageBox.Show("Do something?", "Popup dialog", MessageBoxButtons.YesNo);
          session["SOMEPROP"] = result == DialogResult.Yes ? "True" : "False";
       }
    
       return ActionResult.Success;       
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-17
      • 2012-06-07
      • 2012-02-05
      • 1970-01-01
      • 2012-01-04
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多