1

在安装 WiX 期间,我需要有一个 FileBrowseDialog。我制作了自己的自定义对话框,该对话框引发了 OpenFileDialog 并在会话属性中设置了选定的值(在此处找到代码)。我需要一种方法来使用选定的完整路径刷新编辑控件。现在,选择文件后,编辑控件保持空白。我如何实现这一目标?我不是 MSI 或 WiX 方面的专家。

蜡码

<UI>
  <Dialog Id="DrugsDBFileBrowseDialog" Width="370" Height="270" Title="!(loc.DrugsDBFileDlg_Title)">
    <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.SetupTypeDlgBannerBitmap)" />
    <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
    <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.DrugsDBFileDlgDescription)" />
    <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.DrugsDBFileDlgTitle)" />

    <Control Type="Edit" Id="txtDrugsFilePath" Width="270" Height="15" X="22" Y="142" Property="DRUGSDBFILEPATH" Text="[DRUGSDBFILEPATH]" />
    <Control Type="PushButton" Id="btnBrowse" Width="56" Height="21" X="300" Y="139" Text="&amp;Browse" >          
      <Publish Event="DoAction" Value="BrowseDBFile" Order="0">1</Publish>          
      <Publish Event="SpawnDialog" Value="ValidationErrorDlg" Order="1000">ValidationErrorText</Publish>
    </Control>
    <Control Type="Text" Id="lblInstructions" Width="290" Height="15" X="26" Y="120" Text="!(loc.DrugsDBFileDlgLabelDescription)" />

    <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
    <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
    <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Text="!(loc.WixUINext)" />
    <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
      <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
    </Control>
  </Dialog>
</UI>

自定义操作代码

[CustomAction]
        public static ActionResult BrowseDBFile(Session session)
        {
            try {
                session.Log("Begin OpenFileChooser Custom Action");
                var task = new Thread(() => GetFile(session));
                task.SetApartmentState(ApartmentState.STA);
                task.Start();
                task.Join();
                session.Log("End OpenFileChooser Custom Action");
            } catch (Exception ex) {
                session.Log("Exception occurred as Message: {0}\r\n StackTrace: {1}", ex.Message, ex.StackTrace);
                return ActionResult.Failure;
            }
            return ActionResult.Success;
        }

        private static void GetFile(Session session)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            if (fileDialog.ShowDialog() == DialogResult.OK) {
                session["DRUGSDBFILEPATH"] = fileDialog.FileName;
            }
        }

更新

发现解决方案是在执行与 BROWSE 按钮相关的操作之前调用 RESET 事件。执行自定义操作后,我还执行了 PUBLISH PROPERTY。往下看。

<UI>
      <Dialog Id="DrugsDBFileBrowseDialog" Width="370" Height="270" Title="!(loc.DrugsDBFileDlg_Title)">
        <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.SetupTypeDlgBannerBitmap)" />
        <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
        <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.DrugsDBFileDlgDescription)" />
        <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.DrugsDBFileDlgTitle)" />

        <Control Type="Edit" Id="txtDrugsFilePath" Width="270" Height="15" X="22" Y="142" Property="DRUGSDBFILEPATH" Text="[DRUGSDBFILEPATH]" />
        <Control Type="PushButton" Id="btnBrowse" Width="56" Height="21" X="300" Y="139" Text="&amp;Browse" > 
          <Publish Event="Reset" Value="1">1</Publish> 
          <Publish Event="DoAction" Value="BrowseDBFile" Order="1"><![CDATA[1]]></Publish>
          <Publish Property="DRUGSDBFILEPATH" Value="[DRUGSDBFILEPATH]"><![CDATA[1]]></Publish>
        </Control>
        <Control Type="Text" Id="lblInstructions" Width="290" Height="15" X="26" Y="120" Text="!(loc.DrugsDBFileDlgLabelDescription)" />

        <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
        <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
        <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Text="!(loc.WixUINext)" >   
          <Publish Event="DoAction" Value="ValidateSelectedPath" Order="1">1</Publish>  
          <Publish Event="SpawnDialog" Value="ValidationErrorDlg" Order="1000">ValidationErrorText</Publish>
        </Control>
        <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
          <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
        </Control>
      </Dialog>
    </UI>
4

2 回答 2

2

    <Control Type="Edit" Id="txtDrugsFilePath" Width="270" Height="15" X="22" Y="142" Property="DRUGSDBFILEPATH" Text="[DRUGSDBFILEPATH]" />
    <Control Type="PushButton" Id="btnBrowse" Width="56" Height="21" X="300" Y="139" Text="&amp;Browse" > 
      <Publish Event="Reset" Value="1">1</Publish> 
      <Publish Event="DoAction" Value="BrowseDBFile" Order="1"><![CDATA[1]]></Publish>
      <Publish Property="DRUGSDBFILEPATH" Value="[DRUGSDBFILEPATH]"><![CDATA[1]]></Publish>
    </Control>
    <Control Type="Text" Id="lblInstructions" Width="290" Height="15" X="26" Y="120" Text="!(loc.DrugsDBFileDlgLabelDescription)" />

    <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
    <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
    <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Text="!(loc.WixUINext)" >   
      <Publish Event="DoAction" Value="ValidateSelectedPath" Order="1">1</Publish>  
      <Publish Event="SpawnDialog" Value="ValidationErrorDlg" Order="1000">ValidationErrorText</Publish>
    </Control>
    <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
      <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
    </Control>
  </Dialog>
</UI>
于 2018-11-13T20:53:46.070 回答
0

我对标签做了同样的事情

<Control 
                Type="PushButton" 
                Id="Browse" 
                Width="56" 
                Height="17" 
                X="281" 
                Y="125" 
                Text="Browser"
                Property="FILE_PATH" >
              <Publish Event="DoAction" Value="CA_TO_OPEN_FILE_BROWSER_DIALOG" Order="1">1</Publish>
              <Publish Property="FILE_PATH" Value="[FILE_PATH]">1</Publish>
          </Control>
          
          <Control 
                     Type="Text" 
                     Id="LocationLabel" 
                     Width="244" 
                     Height="15" 
                     X="26" Y="126"
                     Property="FILE_PATH" 
                     Text="[FILE_PATH]" 
                     Sunken="yes" 
                     Indirect="yes" 
                     Disabled="yes">
          </Control>
于 2021-09-30T01:38:33.427 回答