【问题标题】:How to link custom action to control event如何将自定义操作链接到控制事件
【发布时间】:2011-08-24 13:50:21
【问题描述】:

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

我有 2 个项目:

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>

它不像我预期的那样工作,它应该在单击连接按钮时弹出一个消息框。

【问题讨论】:

  • 我看不出你在做什么有什么问题。不过,也许日志中会有一些有用的信息。
  • 感谢您的建议。日志文件显示我的自定义操作程序集无法正确加载。原因是我无意中从配置文件中删除了 codecode 部分。添加回来,现在一切正常。
  • @jcha,如果您发现了原因,最好将其塑造为您自己问题的答案并接受它,以便遇到此线程的其他人确切知道它是如何解决的

标签: wix custom-action wix3.5


【解决方案1】:

我不确定 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;
}

【讨论】:

  • 如果我们包含 System.Windows.Forms 程序集,MessageBox.Show() 应该可以工作。您的示例对我的 WIX 学习非常有用。感谢分享。
  • 感谢您的示例,它帮助我理解了静态文本的工作方式:) Text="[MSGVAR]",我使用的是 Text="MSGVAR",快疯了!
【解决方案2】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多