Named Style WPF in VB.NET

Here we see how to create named styles in wpf using xaml.
  • 2709
Download Files:
 
Here we see how to create named styles in xaml. To do that we create a TextBox and Button control then applying named styles using StaticResource property in XAML.

Named styles

Named styles sheet is the same as inline. Inline CSS is used in HTML. But in WPF we use named style sheet. 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. now creating a Button and TextBox control in xaml to apply named Styles.

<TextBox Height="31" HorizontalAlignment="Left" Margin="95,79,0,0" Name="TextBox1" VerticalAlignment="Top" Width="202" />

<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="155,144,0,0" Name="Button1" VerticalAlignment="Top" Width="75" />

Now apply named styles

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

Style="{StaticResource roh}"

Xaml code

<Window.Resources>

        <Style x:Key="roh">

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

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

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

            <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.

n1.gif

Figure1.gif

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.