How to Create WPF Control Templates

Windows Presentation Foundation (WPF) is a toolset for creating interactive graphical user interfaces (GUI). WPF uses a special language called XAML to place objects in the GUI. XAML is a markup language similar to XML and HTML, and allows beginners to easily modify complex GUI object arrangements. A WPF Control Template allows you to create a default look for a GUI object. You can add them to your project using Visual Studio quite easily.

Things You'll Need

  • Computer with Visual Studio 2010 installed
Show More

Instructions

    • 1

      Open Visual Studio 2010 by clicking on its program icon. When it loads, select "File/New/Project" and click "Visual C#/WPF." A new WPF project is created, and a blank WPF Form appears in the main editor window.

    • 2

      Locate the "Solution Explorer," which should be to the left of the WPF Form. If you cannot find it, click on the menu item "View" and select "Solution Explorer" to reveal it.

    • 3

      Right-click the name of your project. A context menu appears. Select "Add" and then "Resource Dictionary." A dialogue box appears.

    • 4

      Enter any name you wish in the dialogue box and click on "OK" to create a new "Resource Dictionary." This is where you will place your Control Template. The main editor window is automatically switched to the "Resource Dictionary" XAML file. It contains two tags:

      <ResourceDictionary>

      </ResourceDictionary>

    • 5

      Create a Control Template by writing the following code inside the two tags in the "Resource Dictionary" XAML file:

      <ControlTemplate x:Key="MyControlTemplate">

      </ControlTemplate>

Related Searches:

References

Comments

Related Ads

Featured