WIX Combobox绑定值

时间:2013-06-14 03:34:12

标签: wix wix3.5 wix3 wix3.6 wix3.7

我正在尝试使用自定义操作填充值,并希望将值绑定到product.wxs中的组合框中。

如果我想填充组合框内的国家/地区列表,是否有人可以指导我如何绑定值?

我正在努力解决如何传递此值,以便在执行我的MSI设置时值将显示在combox中。

下面提供了我正在尝试的代码:

    public static ActionResult FillList(Session xiSession)
    {

        Dictionary<string, string> _co = new Dictionary<string, string>();
        _co.Add(String.Empty, String.Empty);
        _co.Add("US", "United States");
        _co.Add("CA", "Canada");
        _co.Add("MX", "Mexico");

        xiSession.Log("Return success");
        return ActionResult.Success;
    }

             

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate />

    <Feature Id="ProductFeature" Title="SetupProjectComboTest" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
    </Feature>

<UI>
  <UIRef Id="WixUI_Mondo" />

  <Dialog Id="MyCustomDlg"  Width="500" Height="260">
    <Control Id="ComboBoxMain" Type="ComboBox" X="10" Y="60" Width="300" Height="17" Property="COUNTRIES" />
    <Control Id="ButtonMain" Type="PushButton" X="320" Y="60" Width="40" Height="17" Text="Show">
      <Publish Property="COMBOVALUEFORMATTED" Order="1"  Value="[COUNTRIES]" />
    </Control>
    <Control Id="LabelMain" Type="Text" X="10" Y="80" Width="360" Height="17" Property="COMBOVALUEFORMATTED" Text="[COMBOVALUEFORMATTED]" />

  </Dialog>
</UI>

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="SetupProjectComboTest" />
        </Directory>
    </Directory>
</Fragment>

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
        <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
        <!-- <Component Id="ProductComponent"> -->
            <!-- TODO: Insert files, registry keys, and other resources here. -->
        <!-- </Component> -->
    </ComponentGroup>
</Fragment>

1 个答案:

答案 0 :(得分:2)

您需要在 ComboBox表中插入行以绑定List值。如果在ORCA Editor中打开msi,则可以找到msi表和行。

如果您不在msi中使用任何其他ComboBox元素,则应包含EnsureTable元素。

  <EnsureTable Id="ComboBox"/>

您可以从自定义操作中插入行。

  static int index = 1;
 public static void FillComboBox(Session session, string text, string value)
    {
        View view = session.Database.OpenView("SELECT * FROM ComboBox");
        view.Execute();

        Record record = session.Database.CreateRecord(4);
        record.SetString(1, "COUNTRIES");
        record.SetInteger(2, index);
        record.SetString(3, value);
        record.SetString(4, text);

        view.Modify(ViewModifyMode.InsertTemporary, record);
        view.Close();
        index++;
    }

在自定义操作中调用FillComboBox方法。

   public static ActionResult FillList(Session xiSession)
    {

        FillComboBox(xiSession, "US", "United States");
        FillComboBox(xiSession, "CA", "Canada");
        FillComboBox(xiSession, "MX", "Mexico");          

        return ActionResult.Success;
    }

在运行该组合框对话框之前,在 InstallUIsequence 中执行自定义操作。

   <InstallUISequence>
     <Custom Action="INSERT_ROWS" After="AppSearch">Not Installed</Custom>
  </InstallUISequence>