WiX - как мне обновить элемент управления Edit после диалога просмотра файлов

Мне необходимо иметь FileBrowseDialog во время установки WiX. Я сделал свой собственный диалог, который вызывает OpenFileDialog и устанавливает выбранное значение в свойстве сеанса (нашел код здесь). Мне нужен способ обновить элемент управления Edit выбранным полным путем. Прямо сейчас, после выбора файла, элемент управления остается пустым. Как мне этого добиться? Я не эксперт в MSI или WiX.

Код 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;
            }
        }

ОБНОВИТЬ

Обнаружено, что решение состоит в том, чтобы вызвать событие RESET перед выполнением действия, связанного с кнопкой BROWSE. Я также выполнил 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>

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>

Я сделал то же самое с лейблом

      <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>
Другие вопросы по тегам