Creating a flat button in your Windows Presentation Foundation project is not as complicated as you may think. The default button control provided through the WPF Toolbox lacks a property to display the button as flat, but you can use the “ButtonStyleKey” property through XAML to change the default style of a button control. Changing the style of a button may be a good idea if you plan to create browser-hosted applications.
Instructions
- 1Launch Microsoft Visual Studio and click the “New Project” link. Expand “Other Languages” below Installed Templates and click “Windows.” Double-click “WPF Application” to create a new WPF application.
- 2Click the “XAML” tab located in the bottom of the “MainWindow” screen. Add the following XAML code to create a flat button:<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Height="36" Margin="255,176,135,101" Width="113" Content="Flat button!" Background="#FFEF9999" />
- 3Press the “F5” key to run your program and view the flat button.
- 1