Everyone knows what exactly the Border is. It is a rectangular area used to decorate the UI elements. The main difference between a Rectangle and a Border is that.
Border allows you to add one single child element inside it. Border.Child allows you to include a child DependancyObject inside a Border.
Let us see a sample Border:
<Border Width="50" Height="50" x:Name="brdElement">
<Border.Background>
<SolidColorBrush Color="Bisque"></SolidColorBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect BlurRadius="10" Color="Red" Direction="235"
Opacity=".5" RenderingBias="Quality" ShadowDepth="10" />
</Border.Effect>
</Border>
If you place this in your code you will see something like above. Let us look into detail what exactly I have done.
First of all, Width / Height determines the dimension of the Border element.
Border.Background determines what will be the color of the Brush which will draw the inside of the Border. You can see the color is Bisque. You can define any type of Brush here. SolidColorBrush takes one Color element(which is here defined as Bisque) and fills the Border Background with that color. There are other properties too like CornerRadius, used to create RoundedCorner Border etc. I will discuss them later in the article.
Border Effect can also be applied to a Border. Here I have added a DropShadowEffect. It allows you to put a shadow rendered outside the Border.
The dependency properties that you need to take note are:
1. Color : Defines the Color of the Shadow.
2. Opacity : Fades out the Color. Yo can see the Red color is faded out here to .5; Opacity ranges between 0 - 1.
3. BlurRadius : It defines the extent of shadow radius. Thus if you increase the size of BlurRadius, it will increase the Shadow.
4. Direction : It is the Light Direction in degrees. 235 degree implies where the shadow will focus, thus you can see 360 -235 is the angle where light is placed. Value ranges from 0 to 360.
5. ShadowDepth : It defines the depth of the Shadow. It means, how much the
object is raised from the Shadow. If you increase the value of ShadowDepth, you will see, the being raised.
Now with these lets create a few more :
<Border Width="50" Height="50" x:Name="brdElement">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Red" Offset="0"/>
<GradientStop Color="Pink" Offset=".5"/>
<GradientStop Color="Azure" Offset="1"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect BlurRadius="10" Color="Red"
Direction="45" Opacity=".4" RenderingBias="Performance" ShadowDepth="30" />
</Border.Effect>
</Border>
In the first sample I have modified the SolidColorBrush to LinearGradientBrush with 3 GradientStops. It takes StartPoint and EndPoint. StartPoint defines where the Gradient will start. So 0,0 means starts from the TopLeft corner. First 0 represents the X axis Offset color, and second defines Y - axis Offset color.
Here I have used Gradient from TopLeft to BottomRight, so the Gradient will be straight. GradientStops defines the different colors on the Gradient. Here I have defined all the colors from 0 to 1. Thus the Gradient will start from 0,0 means Red to 1,1 as Azure.
If I start as 0,1 to 1,0 it would have been a Diagonal Gradient.
<Border Width="50" Height="50" x:Name="brdElement" BorderBrush="Goldenrod"
BorderThickness="2">
<Border.Background>
<LinearGradientBrush StartPoint="0,1" EndPoint="1,0">
<LinearGradientBrush.GradientStops>
<GradientStop Color="BurlyWood" Offset="0"/>
<GradientStop Color="MediumBlue" Offset=".5"/>
<GradientStop Color="SlateGray" Offset="1"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect BlurRadius="10" Color="CadetBlue"
Direction="0" Opacity=".4" RenderingBias="Performance" ShadowDepth="15" />
</Border.Effect>
</Border>
In this version, I have modified the Colors of the Gradient. You can see the DropShadow Color, ShadowDepth and Direction is changed as well to demonstrate you how it modifies.
The BorderBrush and BorderThickness defines the border element of the Border.
It means it draws the outer boundary of the Border with.
Border allows you to add one single child element inside it. Border.Child allows you to include a child DependancyObject inside a Border.
Let us see a sample Border:
<Border Width="50" Height="50" x:Name="brdElement">
<Border.Background>
<SolidColorBrush Color="Bisque"></SolidColorBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect BlurRadius="10" Color="Red" Direction="235"
Opacity=".5" RenderingBias="Quality" ShadowDepth="10" />
</Border.Effect>
</Border>
If you place this in your code you will see something like above. Let us look into detail what exactly I have done.
First of all, Width / Height determines the dimension of the Border element.
Border.Background determines what will be the color of the Brush which will draw the inside of the Border. You can see the color is Bisque. You can define any type of Brush here. SolidColorBrush takes one Color element(which is here defined as Bisque) and fills the Border Background with that color. There are other properties too like CornerRadius, used to create RoundedCorner Border etc. I will discuss them later in the article.
Border Effect can also be applied to a Border. Here I have added a DropShadowEffect. It allows you to put a shadow rendered outside the Border.
The dependency properties that you need to take note are:
1. Color : Defines the Color of the Shadow.
2. Opacity : Fades out the Color. Yo can see the Red color is faded out here to .5; Opacity ranges between 0 - 1.
3. BlurRadius : It defines the extent of shadow radius. Thus if you increase the size of BlurRadius, it will increase the Shadow.
4. Direction : It is the Light Direction in degrees. 235 degree implies where the shadow will focus, thus you can see 360 -235 is the angle where light is placed. Value ranges from 0 to 360.
5. ShadowDepth : It defines the depth of the Shadow. It means, how much the
object is raised from the Shadow. If you increase the value of ShadowDepth, you will see, the being raised.
Now with these lets create a few more :
<Border Width="50" Height="50" x:Name="brdElement">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Red" Offset="0"/>
<GradientStop Color="Pink" Offset=".5"/>
<GradientStop Color="Azure" Offset="1"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect BlurRadius="10" Color="Red"
Direction="45" Opacity=".4" RenderingBias="Performance" ShadowDepth="30" />
</Border.Effect>
</Border>
In the first sample I have modified the SolidColorBrush to LinearGradientBrush with 3 GradientStops. It takes StartPoint and EndPoint. StartPoint defines where the Gradient will start. So 0,0 means starts from the TopLeft corner. First 0 represents the X axis Offset color, and second defines Y - axis Offset color.
Here I have used Gradient from TopLeft to BottomRight, so the Gradient will be straight. GradientStops defines the different colors on the Gradient. Here I have defined all the colors from 0 to 1. Thus the Gradient will start from 0,0 means Red to 1,1 as Azure.
If I start as 0,1 to 1,0 it would have been a Diagonal Gradient.
<Border Width="50" Height="50" x:Name="brdElement" BorderBrush="Goldenrod"
BorderThickness="2">
<Border.Background>
<LinearGradientBrush StartPoint="0,1" EndPoint="1,0">
<LinearGradientBrush.GradientStops>
<GradientStop Color="BurlyWood" Offset="0"/>
<GradientStop Color="MediumBlue" Offset=".5"/>
<GradientStop Color="SlateGray" Offset="1"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect BlurRadius="10" Color="CadetBlue"
Direction="0" Opacity=".4" RenderingBias="Performance" ShadowDepth="15" />
</Border.Effect>
</Border>
In this version, I have modified the Colors of the Gradient. You can see the DropShadow Color, ShadowDepth and Direction is changed as well to demonstrate you how it modifies.
The BorderBrush and BorderThickness defines the border element of the Border.
It means it draws the outer boundary of the Border with.


 
No comments:
Post a Comment