WPF Web Based

WPF Examples

WPF

WPF Projects

WPF Project

adplus-dvertising
Label Control in WPF Web Base
Previous Home Next

Creating a Label:

The Label element represents a WPF Label control in XAML.

<Label/>

The Width and Height attributes of the Label element represent the width and the height of a Label. The Content property of the Label element sets the text of a Label. The Name attribute represents the name of the control, which is a unique identifier of a control.

The code snippet in Listing 1 creates a Label control and sets the name, height, width, and content of a Label control. The code also sets the font format for the text.

Code for label control:

<Label Margin="19,31,9.156,0" Name="label1" Height="28" 
         VerticalAlignment="Top" Background="Teal" 
       Foreground="Cornsilk" Grid.ColumnSpan="2">Label</Label>
<Button Height="23" Margin="19,87,19.14,0" Name="button1" 
      VerticalAlignment="Top" Click="button1_Click">Click Me</Button>
<Button Grid.Column="1" Height="23" Margin="0,87,9.156,0"
         Name="button2" VerticalAlignment="Top"
		 Click="button2_Click">Cance
l</Button>
Output:
Formatting a Label

The BorderBrush property of the Label sets a brush to draw the border of a Label. You may use any brush to fill the border. The following code snippet uses a linear gradient brush to draw the border with a combination of red and blue color.

<Label.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1" >
<GradientStop Color="Blue" Offset="0" />
<GradientStop Color="Red" Offset="1.0" />
</LinearGradientBrush>
</Label.BorderBrush>

The Background and Foreground properties of the Label set the background and foreground colors of a Label. You may use any brush to fill the border. The following code snippet uses linear gradient brushes to draw the background and foreground of a Label.

<Label.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1" >
<GradientStop Color="Blue" Offset="0.1" />
<GradientStop Color="Orange" Offset="0.25" />
<GradientStop Color="Green" Offset="0.75" />
<GradientStop Color="Black" Offset="1.0" />
</LinearGradientBrush>
</Label.Background>
<Label.Foreground>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1" >
<GradientStop Color="Orange" Offset="0.25" />
<GradientStop Color="Green" Offset="1.0" />
</LinearGradientBrush>
</Label.Foreground>

The new Label looks like Figure.

LabelImg4.jpg
Setting Image as Background of a Label

To set an image as background of a Label, we can set an image as the Background of the Label. The following code snippet sets the background of a Label to an image.

<Label.Background>
<ImageBrush ImageSource="Garden.jpg" />
</Label.Background>
Previous Home Next
WPF Examples

WPF

WPF

WPF

WPF

WPF

WPF

WPF

WPF