Share via


Defining a User Interface Value Editor

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

For some fields, you may want to implement a user interface component to help the user edit a field value. For example, in a date field, you may want a calendar component to appear to help the user choose a particular date.

To use a User Interface Value Editor (also known simply as a value editor), you need to specify the editor class, by using the <Editor> attribute of the <Field> element of the wizard. The following XML code example shows a field named ValueName with an associated editor. This editor is implemented by the MessageEditor class and it collects a string from the user.

<Wizard xmlns="https://schemas.microsoft.com/pag/gax-wizards" SchemaVersion="1.0">
  <Pages>
    <Page>
      <Title>Collect message to show</Title>
      <LinkTitle>Provide a message that will be used by the HelloWorldAction.</LinkTitle>
      <Help>You shouldn't need a lot of help!</Help>
      <Fields>
        <Field ValueName="Message" Label="Message">
        <Editor Type="PackageNamespace.Editors.MessageEditor, PackageName" />
        </Field>
      </Fields>
    </Page>
  </Pages>
</Wizard>

If the editor is not specified explicitly, the Recipe Framework still tries to determine and load the correct editor to use, by analyzing the type of the argument. The following XML code example shows an argument in the NewItemClass recipe of the type System.DateTime. In this case, the DateTime type has an editor associated with it. This is loaded by the framework even though it has not been specified explicitly in the configuration file.

The argument also has a value provider that sets its initial value to the current date and time.

<Argument Name="Date" Type="System.DateTime">
  <ValueProvider Type="PackageNamespace.ValueProviders.DateNowValueProvider, PackageName" />
</Argument>

The Recipe Framework includes the SolutionPickerEditor value editor. The editor allows the user to select a solution element, such as a project, solution folder, or an project item.

The NewItemClass recipe shows how the editor is used. In this recipe a new class is created in a project selected by the user. The recipe creates a new class in a project selected by the user. One of the recipe arguments, the Project argument, is of type EnvDTE.Project, as shown in the following XML snippet.

<Argument Name="Project" Type="EnvDTE.Project, EnvDTE">
  <!-- Converter ensures that a string representation of a project is valid, and also allows conversion to/from it to the Project instance. -->
  <Converter Type="Microsoft.Practices.RecipeFramework.Library.Converters.ProjectConverter, Microsoft.Practices.RecipeFramework.Library" />
</Argument>

The value of that argument is collected by the user in a wizard. The field corresponding to the argument is defined as follows.

<Field ValueName="Project" Label="Reference Project">
  <Tooltip>Shows a complex editor for selecting a project in the current solution, provided with the Library.</Tooltip>
  <Editor Type="Microsoft.Practices.RecipeFramework.Library.Editors.SolutionPickerEditor, Microsoft.Practices.RecipeFramework.Library" />
</Field>

When you use the SolutionPickerEditor value editor in a wizard, you should ensure that the associated argument always has the right type converter defined, or the name of the selected solution element will not show up in the wizard field. In the case of this example, the right converter is ProjectConverter.

Note

An editor may use services from other components, including Visual Studio itself. For more information, see Obtaining and Using Host Services.

See also

Developing Wizards | Defining a Wizard | Writing Type Converters | Writing a Custom Wizard Page | Implementing Argument Value Propagation