ARTICLE

Named styles in WPF using VB.NET

Posted by Rohatash Kumar Articles | WPF using VB.NET February 01, 2011
In this article we will learn how to use named styles in WPF using VB.NET.
Download Files:
 
Reader Level:

In this article we will learn how to use Named Styles in WPF using VB.NET.

Named styles

The named styles has a name and we use that name on the control with the style property.

For example

This example describes the named styles.

Drag and drop the Button and TextBox control on the form.

s1.gif

Figure 1.

Now applying the styles on these control.

StaticResource - StaticResource is used to get reference of the style.

Style="{StaticResource roh}"

Xaml code

<Window x:Class="MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="MainWindow" Height="350" Width="525">

   <Window.Resources>

<Style x:Key="roh">

   <Setter Property="Control.FontSize" Value="32" />

   <Setter Property="Control.FontWeight" Value="Bold" />

   <Setter Property="Control.Background" Value="red"/>

   <Setter Property="Control.Foreground" Value="green" />

  </Style>

        </Window.Resources>

    <Grid >

<Button Content="Button" Height="72" Name="Button1" Width="176" Style="{StaticResource roh}" Margin="154,174,173,65" />

        <TextBox Height="72" HorizontalAlignment="Left" Margin="81,76,0,0" Name="TextBox1" VerticalAlignment="Top" Width="331" Style="{StaticResource roh}" Text="This is a textBox." />

    </Grid>

</Window>

Now run the application and test it.

s2.gif

Figure 2.

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor