这一篇文章将为大家介绍如何使用WIX自定义UI。上一篇文章我们讲过WIX为我们提供了五种安装界面。每种安装界面都是由不同的Dialog组成。在这里我们挑选一种比较常用的界面WixUI_FeatureTree Dialog Set
来为大家介绍一下。
在WixUI_FeatureTree Dialog Set
中一共包含了如下几种Dialog。
First-time install dialog sequence:
- WixUI_WelcomeDlg
- WixUI_LicenseAgreementDlg
- WixUI_CustomizeDlg - WixUI_VerifyReadyDlg - WixUI_DiskCostDlg Maintenance dialog sequence: - WixUI_MaintenanceWelcomeDlg - WixUI_MaintenanceTypeDlg - WixUI_CustomizeDlg - WixUI_VerifyReadyDlg Patch dialog sequence: - WixUI_WelcomeDlg - WixUI_VerifyReadyDlg
通过其中的注释我们可以看到:当我们程序第一次安装的时候我们所看见的界面顺序应该是:
- WixUI_WelcomeDlg 欢迎界面
- WixUI_LicenseAgreementDlg 协议同意
- WixUI_CustomizeDlg 自定义功能选择 - WixUI_VerifyReadyDlg 确认安装界面 - WixUI_DiskCostDlg 磁盘消耗
在WIX上处界面中(除开WixUI_WelcomeDlg之外)每个界面上都有三个按钮:next
back
和 cancel
。其中next
和 back
把这所有的界面组成一个双向链表。如果我们需要完全自定义一个界面,我们只需要在界面定义完成之后,把它加入到这个双向链表中来。这样我们自定义的界面就可以显示来。具体操作如下。
- 创建Dialog。在项目中添加一个文件
customDialog.wxs
并且添加代码如下:
<!--
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<UI>
<Dialog Id="DatabaseInformationDlg" Width="370" Height="270" Title="[ProductName] [Setup]" NoMinimize="yes">
<Control Id="ServerLabel" Type="Text" X="20" Y="62" Width="80" Height="25" NoPrefix="yes" Text="SQL Database:" />
<Control Id="Server" Type="ComboBox" Height="16" Width="180" X="110" Y="60" Property="DATABASE_SERVER">
<ComboBox Property="DATABASE_SERVER">
<ListItem Text="[DATABASE_SERVER]" Value="[DATABASE_SERVER]" />
</ComboBox>
</Control>
<Control Id="DatabaseType" Type="RadioButtonGroup" X="20" Y="100" Width="290" Height="40" Property="DATABASE_LOGON_TYPE">
<RadioButtonGroup Property="DATABASE_LOGON_TYPE">
<RadioButton Value="DatabaseIntegratedAuth" X="0" Y="0" Width="290" Height="16" Text="Trusted (Windows Authentication)" />
<RadioButton Value="DatabaseAccount" X="0" Y="20" Width="290" Height="16" Text="Specify Username and Password (SQL Authentication)" />
</RadioButtonGroup>
</Control>
<!-- Login -->
<Control Type="Text" Id="UsernameLabel" Width="50" Height="15" X="40" Y="150" Text="&Login:"> <Condition Action="disable"><![CDATA[DATABASE_LOGON_TYPE <> "DatabaseAccount"]]></Condition> <Condition Action="enable"><![CDATA[DATABASE_LOGON_TYPE = "DatabaseAccount"]]></Condition> </Control> <Control Id="Username" Type="Edit" X="110" Y="145" Width="180" Height="18" Property="DATABASE_USERNAME" Text="{80}"> <Condition Action="disable"><![CDATA[DATABASE_LOGON_TYPE <> "DatabaseAccount"]]></Condition> <Condition Action="enable"><![CDATA[DATABASE_LOGON_TYPE = "DatabaseAccount"]]></Condition> </Control> <!-- Password --> <Control Type="Text" Id="PasswordLabel" Width="50" Height="15" X="40" Y="173" Text="&Password:"> <Condition Action="disable"><![CDATA[DATABASE_LOGON_TYPE <> "DatabaseAccount"]]></Condition> <Condition Action="enable"><![CDATA[DATABASE_LOGON_TYPE = "DatabaseAccount"]]></Condition> </Control> <Control Id="Password" Type="Edit" X="110" Y="170" Width="180" Height="18" Property="DATABASE_PASSWORD" Text="{80}" Password="yes" > <Condition Action="disable"><![CDATA[DATABASE_LOGON_TYPE <> "DatabaseAccount"]]></Condition> <Condition Action="enable"><![CDATA[DATABASE_LOGON_TYPE = "DatabaseAccount"]]></Condition> </Control> <Control Id="Test" Type="PushButton" X="40" Y="197" Width="100" Height="17" Text="Test Connection"> <Condition Action="disable"><![CDATA[DATABASE_SERVER = ""]]></Condition> <Condition Action="enable"><![CDATA[DATABASE_SERVER <> ""]]></Condition> <!--test connection--> <Publish Event="DoAction" Value="VerifySqlConnection" Order="1">1</Publish> <Publish Event="SpawnDialog" Value="InvalidLogonDlg" Order="2"><![CDATA[NOT CONNECT_SUCCEED]]></Publish> </Control> <!-- Back button --> <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="&Back"></Control> <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&Next"></Control> <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">