Menu

Deep Dive into WPF — Style
📰

Deep Dive into WPF — Style

DEV Community: dotnet·yohan·about 5 hours ago
#34PXWHif
#devtodotnet#devto#dev#style#control
Reading 0:00
15s threshold

Style is used to share properties, resources, and event handlers across different instances of a type. You can think of a Style as a shortcut for applying a set of property values to multiple elements.

That is MSDN’s description of Style—fairly conventional, as translations go. Put simply, Style is a batch operation on property values. Much like CSS on the web, it lets you apply a whole set of property values to UI elements at once.

Example

The simplest Style example:

<Window> <Grid> <Grid.Resources> <Style TargetType= "{x:Type Button}" x:Key= "ButtonStyle" > <Setter Property= "Height" Value= "22" /> <Setter Property= "Width" Value= "60" /> </Style> </Grid.Resources> <Button Content= "Button" Style= "{StaticResource ButtonStyle}" /> <Button Content= "Button" Style= "{StaticResource ButtonStyle}" Margin= "156,144,286,145" /> </Grid> </Window>

Enter fullscreen mode

Exit fullscreen mode

For Resources, see MSDN . Here we create a ButtonStyle whose target type is Button.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.