Using Silverlight Border Control

This article shows how to use Border control in Silverlight.
  • 2876

Border is a silverlight control is used to put border to controls, text, and images.

<!--Border with CornerRadius property -->

<Border CornerRadius="10" BorderBrush="DarkGreen" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" BorderThickness="2"  Margin="2,2,2,2" Grid.Row="0" Grid.Column="0">
 
   <TextBlock Text="Border Example" Margin="50,2,2,2" ></TextBlock>
</Border>

1.jpg
 

Figure1.

<!--Border -->

 <Border BorderBrush="DarkGreen" Width="200" Height="150" BorderThickness="4"  Margin="2,2,2,2" Grid.Row="1" Grid.Column="0">
</Border>

2.jpg
 

 Figure2.

<!--Border with Brush -->

 
<Border x:Name="ex" BorderThickness="4" Width="200" Height="150" Grid.Row="2" Grid.Column="0" CornerRadius="10">
 
   <Border.BorderBrush>
 
       <LinearGradientBrush x:Name="borderLinearGradientBrush" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0" EndPoint="0.5,1">
 
           <LinearGradientBrush.GradientStops>
 
               <GradientStop Color="Red" Offset="0" />
 
               <GradientStop Color="Purple" Offset="1" />
 
           </LinearGradientBrush.GradientStops>
 
       </LinearGradientBrush>
 
   </Border.BorderBrush
</Border>

3.jpg
 

 Figure3.

<!--Border with ImageBrush -->

<Border CornerRadius="20" x:Name="border1" BorderBrush="Black" BorderThickness="4" Width="300" Height="250" Grid.Row="3" Grid.Column="0">
 
   <Border.Background>
 
       <ImageBrush x:Name="backgroundImageBrush" Stretch="UniformToFill">
 
           <ImageBrush.ImageSource>
 
               <BitmapImage x:Name="img" UriSource="Raj 039.JPG">
 
               </BitmapImage>
 
           </ImageBrush.ImageSource>
 
       </ImageBrush>
 
   </Border.Background>
</
Border>

4.jpg
 


Figure4.

<!-- Border with MouseLeave and MouseLeftButtonDown click-->

 
<Border x:Name="ClickBorder" BorderThickness="2" Grid.Row="0" Grid.Column="1" >
 
   <Border.BorderBrush>
 
       <SolidColorBrush Color="Green" Opacity="0" />
 
   </Border.BorderBrush>
 
   <TextBlock
              MouseLeftButtonDown="TextBlock_MouseLeftButtonDown"   MouseLeave
="TextBlock_MouseLeave"
               Text
="RAJ BENIWAL" />

</
Border>

private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
     ClickBorder.BorderBrush.Opacity = 1;
}

  private void TextBlock_MouseLeave(object sender, MouseEventArgs e)
{
     ClickBorder.BorderBrush.Opacity = 0;
}

5.jpg
 

 
Figure5.

6.jpg
 

Figure6.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.