- WPF Tutorial
- WPF - Home
- WPF - Overview
- WPF - Environment Setup
- WPF - Hello World
- WPF - XAML Overview
- WPF - Elements Tree
- WPF - Dependency Properties
- WPF - Routed Events
- WPF - Controls
- WPF - Layouts
- WPF - Nesting Of Layout
- WPF - Input
- WPF - Command Line
- WPF - Data Binding
- WPF - Resources
- WPF - Templates
- WPF - Styles
- WPF - Triggers
- WPF - Debugging
- WPF - Custom Controls
- WPF - Exception Handling
- WPF - Localization
- WPF - Interaction
- WPF - 2D Graphics
- WPF - 3D Graphics
- WPF - Multimedia
- WPF Useful Resources
- WPF - Quick Guide
- WPF - Useful Resources
- WPF - Discussion
WPF - Layout Level
Defining a style on any layout level will make it accessible by that layout and its child elements only. Given below is an example of layout level where all the three buttons have common style.
<Window x:Class = "XAMLLayoutLevelStyle.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" Title = "MainWindow" Height = "350" Width = "604"> <StackPanel Margin = "10"> <StackPanel.Resources> <Style TargetType = "Button"> <Setter Property = "Foreground" Value = "Blue" /> <Setter Property = "FontStyle" Value = "Italic" /> <Setter Property = "Width" Value = "100" /> <Setter Property = "Height" Value = "40" /> <Setter Property = "Margin" Value = "10" /> </Style> </StackPanel.Resources> <Button>Button 1</Button> <Button>Button 2</Button> <Button Foreground = "Blue">Button 3</Button> </StackPanel> </Window>
When you compile and execute the above code, it will produce the following window.
wpf_styles.htm
Advertisements