--- title: "Walkthrough: Style WPF content" ms.date: "03/30/2017" helpviewer_keywords: - "WPF Designer [Windows Forms], styling WPF content" - "interoperability [WDF]" - "styles [Windows Forms], WPF content" ms.assetid: e574aac7-7ea4-4cdb-8034-bab541f000df --- # Walkthrough: Style WPF content This article show you how to apply styling to a Windows Presentation Foundation (WPF) control hosted on a Windows Form. ## Prerequisites You need Visual Studio to complete this walkthrough. ## Create the project Open Visual Studio and create a new Windows Forms Application project in Visual Basic or Visual C# named `StylingWpfContent`. > [!NOTE] > When hosting WPF content, only C# and Visual Basic projects are supported. ## Create the WPF control types After you add a WPF control type to the project, you can host it in an control. 1. Add a new WPF project to the solution. Use the default name for the control type, `UserControl1.xaml`. For more information, see [Walkthrough: Creating New WPF Content on Windows Forms at Design Time](walkthrough-creating-new-wpf-content-on-windows-forms-at-design-time.md). 2. In Design view, make sure that `UserControl1` is selected. 3. In the **Properties** window, set the value of the and properties to **200**. 4. Add a control to the and set the value of the property to **Cancel**. 5. Add a second control to the and set the value of the property to **OK**. 6. Build the project. ## Apply a Style to a WPF Control You can apply different styling to a WPF control to change its appearance and behavior. 1. Open `Form1` in the Windows Forms Designer. 1. In the **Toolbox**, double-click `UserControl1` to create an instance of `UserControl1` on the form. An instance of `UserControl1` is hosted in a new control named `elementHost1`. 1. In the smart tag panel for `elementHost1`, click **Edit Hosted Content** from the drop-down list. `UserControl1` opens in the WPF Designer. 1. In XAML view, insert the following XAML after the `` opening tag. This XAML creates a gradient with a contrasting gradient border. When the control is clicked, the gradients are changed to generate a pressed button look. For more information, see [Styling and Templating](/dotnet/desktop-wpf/fundamentals/styles-templates-overview). ```xaml ``` 1. Apply the `SimpleButton` style defined in the previous step to the Cancel button by inserting the following XAML in the ` ``` 1. Build the project. 1. Open `Form1` in the Windows Forms Designer. 1. The new style is applied to the button control. 1. From the **Debug** menu, select **Start Debugging** to run the application. 1. Click the **OK** and **Cancel** buttons and view the differences. ## See also - - - [Migration and Interoperability](/dotnet/framework/wpf/advanced/migration-and-interoperability) - [Using WPF Controls](using-wpf-controls.md) - [Design XAML in Visual Studio](/visualstudio/xaml-tools/designing-xaml-in-visual-studio) - [XAML Overview (WPF)](/dotnet/desktop-wpf/fundamentals/xaml) - [Styling and Templating](/dotnet/desktop-wpf/fundamentals/styles-templates-overview)