0

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

4

2 回答 2

3

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

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>

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

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

调用对话框的代码:

<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>
于 2013-10-28T18:13:03.497 回答
0

为此找到了另一种解决方案。它是从自定义操作中使用 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;       
}
于 2014-03-06T11:38:06.667 回答