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

发布于 2024-12-01 05:02:14 字数 1012 浏览 0 评论 0原文

我正在研究 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>

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

I'm studying Wix to build product installer. I've customized the UI successfully but be wondering how to link a custom action to control event (i.e PushButton).

I have 2 projects:

Product.Wix.CustomActions

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

Product.Wix.Setup (referenced to Product.Wix.CustomActions project). In Setup.wxs, I have declared a custom action:

<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' />

I have a custom dialog with Connect button and wiring to the action as below:

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

It does not work as I expected it should pop-up a message box when clicking on the Connect button.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黯然#的苍凉 2024-12-08 05:02:14

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

示例

<Control Id="TestConn" Type="PushButton" X="265" Y="205" Width="70" Height="18" Text="&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;
}

Am not sure whether MessageBox.Show() will work. Also its better to go with WIX dialogs as you can capture the option selected by user on the popup.

Example

<Control Id="TestConn" Type="PushButton" X="265" Y="205" Width="70" Height="18" Text="&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>

Custom Action

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
    session["MSGVAR"] = "Some Message";
    return ActionResult.Success;
}
橙幽之幻 2024-12-08 05:02:14

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

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

从配置文件中 删除了以下部分:将其添加回来,现在一切正常。

The log file shows my custom action assemblies could not be loaded properly. The reason is I have unintentionally removed the section:

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

from the config file. Added it back and everything works now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文