如何将自定义操作链接到控件事件

时间:2011-08-24 13:50:21

标签: wix custom-action wix3.5

我正在研究Wix来构建产品安装程序。我已成功定制UI,但想知道如何将自定义动作链接到控制事件(即PushButton)。

我有两个项目:

Product.Wix.CustomActions

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
 session.Log("Begin CustomAction1");
 MessageBox.Show("CustomActions1");
 return ActionResult.Success;
}

Product.Wix.Setup (引用Product.Wix.CustomActions项目)。在Setup.wxs中,我声明了一个自定义操作:

<Binary Id="CustomActions" SourceFile="..\Product.Wix.CustomActions\bin\Debug\Product.Wix.CustomActions.CA.dll" />
<CustomAction Id='Action1' BinaryKey='CustomActions' DllEntry='CustomAction1' Execute='immediate' Return='check' />

我有一个带有连接按钮的自定义对话框,并连接到操作,如下所示:

<Control Id="Connect" Type="PushButton" X="325" Y="75" Width="30" Height="17" Text="...">
<Publish Event="DoAction" Value="Action1">1</Publish>
</Control>

它不起作用,因为我预期它应该在单击“连接”按钮时弹出一个消息框。

2 个答案:

答案 0 :(得分:4)

我不确定MessageBox.Show()是否有效。最好使用WIX对话框,因为您可以在弹出窗口中捕获用户选择的选项。

实施例

<Control Id="TestConn" Type="PushButton" X="265" Y="205" Width="70" Height="18" Text="&amp;Test Connection">
    <Publish Event="DoAction" Value="Action1">1</Publish>
    <Publish Property="ERRORMSG" Value="CustomActions1">ACCEPTED = "1"</Publish>
    <Publish Event="SpawnDialog" Value="InvalidDBConnDlg">ACCEPTED = "0"</Publish>
</Control>

<Dialog Id="InvalidDBConnDlg" Width="260" Height="120" Title="[ProductName]">
    <Control Id="OK" Type="PushButton" X="102" Y="90" Width="56" Height="17" Default="yes" Cancel="yes" Text="OK" />
    <Control Id="Text" Type="Text" X="48" Y="22" Width="194" Height="60" Text="[MSGVAR]" />
    <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Information icon" FixedSize="yes" IconSize="32" Text="WixUI_Ico_Info" />
</Dialog>

自定义操作

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
    session["MSGVAR"] = "Some Message";
    return ActionResult.Success;
}

答案 1 :(得分:2)

日志文件显示我的自定义操作程序集无法正确加载。原因是我无意中删除了该部分:

<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>

来自配置文件。添加回来,现在一切正常。