使用 WiX 浏览器对话框设置编辑框值 [英] Use WiX browser dialog to set edit box value

查看:25
本文介绍了使用 WiX 浏览器对话框设置编辑框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 WiX 安装程序对话框,该对话框提供了一系列用户需要填写目录位置的文本框.

I'm trying to create a WiX installer dialog that provides a series of textboxes that users need to fill in with directory locations.

我想做的是在每个对话框旁边放一个浏览按钮,当他们单击它时,会出现 WiX 浏览对话框,他们选择一个文件位置,单击确定,然后浏览按钮旁边的文本框将被填写.

What I would like to do is put a Browse button next to each dialog and when they click it, the WiX Browse dialog will come up, they select a file location, click OK, and the text box next to the browse button will be filled in.

我知道如何使用自定义操作来做到这一点,但我想知道是否有一种纯粹的 WiX 方式来做到这一点.

I know how to do it with a custom action, but I was wondering if there was a pure WiX way of doing this.

我应该更清楚.我的意思是目录位置,而不是文件位置.Wix 没有如下所示的一位用户支持文件浏览.

I should be more clear. I meant directory locations, not file locations. Wix doesn't have file browsing support as one user indicated below.

推荐答案

我最终找到了一种完全在 Wix 中完成的方法.Wix 带有一个名为 BrowseDlg 的浏览对话框.这是我所做的:

I did end up finding a way to do it completely in Wix. Wix comes with a browse dialog called BrowseDlg. Here's what I did:

  1. 我创建了一个包含 PathEdit 控件和 PushButton 控件的对话框.请注意,PathEdit 控件的 Indirect 属性设置为 yes.这意味着无论您将 Property 设置为什么,都只是指向其他内容的指针.

  1. I created a dialog that includes a PathEdit control and PushButton control. Notice that the PathEdit control has the Indirect property set to yes. This means that whatever you set Property to is just a pointer to something else.

    <Dialog Id="BackupConfigDlg" Width="370" Height="270" Title="Backup Configuration">
        <Control Type="Text" Id="lblInstructions" Width="348" Height="13" X="10" Y="10">
            <Text>{\WixUI_Font_Title}Please select the directory you want to backup.</Text>
        </Control>
        <Control Type="Text" Id="lblBackupDirectory" Width="69" Height="9" X="10" Y="40" Text="Backup directory:">
        </Control>
        <Control Type="PathEdit" Id="Folder" Width="219" Height="15" X="82" Y="38" Property="_BrowseProperty" Indirect="yes" />
        <Control Type="PushButton" Id="Browse" Width="56" Height="17" X="304" Y="37" Text="Browse..." />
        <Control Type="Line" Id="line" Width="362" Height="2" X="4" Y="229" />
        <Control Id="Cancel" Type="PushButton" X="239" Y="240" Width="56" Height="17" Cancel="yes" Text="Cancel">
            <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
        </Control>
        <Control Type="PushButton" Id="Install" Width="56" Height="17" X="300" Y="240" Text="Install">
            <Publish Event="EndDialog" Value="Return" />
        </Control>
    </Dialog>

  • 浏览对话框(我们最终会看到)希望在 Directory 表中设置一个对象,因此我们需要创建一个 Directory 对象,该对象将仅用于保存我们浏览到的值.由于我们不会在其中放置任何组件,因此文件系统上的任何内容都不会与我们选择的目录相关.我称我的为 TARGETBACKUPDIRECTORY.

  • The browse dialog (that we'll eventually get to) expects to set an object in the Directory table, so we need to create a Directory object that will only be used to hold the value we browse to. Since we won't put any components in it, nothing on the file system will change relating to the directory we choose. I call mine TARGETBACKUPDIRECTORY.

        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="TARGETBACKUPDIRECTORY">
            </Directory>
            ...
        </Directory>
    

  • 现在我们需要创建一个指向 Directory 对象的属性.

  • Now we need to create a property that points to the Directory object.

    <Property Id="BACKUPDIRECTORY" Value="TARGETBACKUPDIRECTORY" />
    

  • 我们现在需要确保 _BrowserProperty 属性正确绑定到 BACKUPDIRECTORY(因为它指向我们要设置的 Directory 对象),然后此对话框打开.如果不这样做,当您尝试打开对话框时,您将在安装过程中收到错误消息.在我的示例中,PrevDlg 是一个出现在 BackupConfigDlg 之前的对话框.这里发生的事情是,当按下 Next 按钮时,我将 _BrowserProperty 属性设置为 BACKUPDIRECTORY,然后打开对话框.它必须按该顺序发生,因此我使用 Order 属性来强制执行它.当浏览按钮被按下时,我会做同样的事情,我不确定我需要这样做,但我这样做只是为了安全措施.

  • We now need to make sure that the _BrowserProperty property is properly bound to BACKUPDIRECTORY (because it points to the Directory object we want set) before this dialog opens. If you don't, you will get an error during the install process when you attempt to open the dialog. In my example, PrevDlg is a dialog that appears before BackupConfigDlg. What's happening here is that when the Next button is pushed, I set the _BrowserProperty property to BACKUPDIRECTORY, I then open the dialog. It must take place in that order so I use the Order property to enforce it. I do the same thing when the browse button is pushed, not sure I need to do, but I do it just for safe measure.

        <Publish Dialog="PrevDlg" Control="Next" Property="_BrowseProperty" Value="[BACKUPDIRECTORY]" Order="1">1</Publish>
        <Publish Dialog="PrevDlg" Control="Next" Event="NewDialog" Value="BackupConfigDlg" Order="2">1</Publish>
        <Publish Dialog="BackupConfigDlg" Control="Browse" Property="_BrowseProperty" Value="[BACKUPDIRECTORY]" Order="1">
        </Publish>
        <Publish Dialog="BackupConfigDlg" Control="Browse" Event="SpawnDialog" Value="BrowseDlg" Order="2">
        </Publish>
    

  • 这对我有用.

    这篇关于使用 WiX 浏览器对话框设置编辑框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆