Skip to Content
Professional Visual Basic 2012 and .NET 4.5 Programming
book

Professional Visual Basic 2012 and .NET 4.5 Programming

by Bill Sheldon, Billy Hollis, Rob Windsor, David McCarter, Gastón Hillar, Todd Herman
January 2013
Intermediate to advanced
912 pages
26h 58m
English
Wrox
Content preview from Professional Visual Basic 2012 and .NET 4.5 Programming

Styles

Developers of business applications might be a bit wary of becoming an expert in styling. Windows Forms had no such capability, and web applications often have specialists that do the styling.

However, styles in XAML are quite a bit more flexible than styles in earlier technologies, and address functionality that's not strictly cosmetic. That means developers need to understand styles, too.

What Is a Style?

At the most basic level, a Style in XAML is simply a way to set several property values for an element at one time. In syntactical terms, a Style is a collection of Setter objects, and each Setter object knows how to set a particular property to a particular value.

Here is a simple Style for a Button element (code file: SimpleStyle.xaml):

<Style x:Key="ButtonStyle" TargetType="Button">
    <Setter Property="Margin" Value="4" />
    <Setter Property="FontSize" Value="22"/>
    <Setter Property="FontStyle" Value="Italic" />
    <Setter Property="Foreground" >
        <Setter.Value>
            <LinearGradientBrush
                EndPoint="0.8,0.8" 
                StartPoint="0.2,0.2">
                <GradientStop Color="DarkBlue" Offset="0"/>
                <GradientStop Color="ForestGreen" Offset="1"/>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
</Style>

In this case, the Style is declared as a resource, and so has an x:Key attribute. That's the common case. There are a few scenarios where a Style is not used as a resource, and in fact you will see one a bit further on. However, normally the power of a Style is to apply it widely through much or all of an application, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Visual Basic 2012 Programmer's Reference

Visual Basic 2012 Programmer's Reference

Rod Stephens

Publisher Resources

ISBN: 9781118332139Purchase book