简体   繁体   中英

WiX - how do I refresh Edit control after file browse dialog

I am required to have a FileBrowseDialog during a WiX installation. I made my own custom dialog that raises the OpenFileDialog and sets the selected value in the session property (found the code here ). I need a way to refresh the Edit control with the selected full path. Right now, after choosing the file, the edit control remains blank. How do I achieve this? I am not an expert in MSI or WiX.

Wix Code :

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

Custom Action Code :

[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;
            }
        }

UPDATE

Found out the solution is to invoke the RESET event before performing the action associated to the BROWSE button. I also performed a PUBLISH PROPERTY after performing the custom action. Look below.

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

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

I did the same with the label

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM