Brushes in Silverlight

Brushes fill the background ,foreground and border of an element.
System.Windows.Media.Brush provides 5 brush classes:
SolidColorBrush
RadialGradientBrush
LinearGradientBrush
ImageBrush
VideoBrush

We shall discuss here about linear and radial brushes.

LinearGradientBrush
Fills element horizontally,vertically or diagonally in linear fashion
GradientStop : Offset can take values from 0 to 1
0: Beginning color of gradient
1: End color of gradient
In order to decide the direction of fill two properties are used:
StartPoint EndPoint
(0,0)            (1,1) : Diagonal Fill
(0,1)             (1,1) : Vertical side-to-side fill
(1,0)            (1,1) : Horizontal top to bottom fill

RadialGradientBrush
Fills element radially and gradiates out from a inner gradient circle.
Inner Gradient circle used 3 properties
RadiusX,RadiusY: to limit the size
GradientOrigin property: Sets the location of point within
the element.
GradientStops can take values from (0,0) to (1,1).

In figure below:
The grid is divided into 2 rows and 4 columns.
For lineargradientbrush the startpoint and the endpoint
values are changed for each rectangle.
Code for one rectangle:
code11

For radialgradient brush the gradientorigin is changed for every ellipse.
Code for one ellipse:
code2

LinearGradientBrush and RadialGradientBrush

“NTLDR is missing” problem solved in Windows XP.

You switch on your pc,select the OS and find what
NTLDR missing!!! Cant get in?
Here’s the solution..

What is NTLDR?
NTLDR is the boot loader for Windows NT operating systems including
Windows XP.It runs from primary hard drive to load the OS selected from
the startup menu with the help of boot sector in a file.

Components important to load OS:
NTLDR: contains boot loader
boot.ini : system file which stores list of Operating Systems
to be shown at start up .
ntdetect.com: detects basic hardware required to start the operating system.
ntoskrnl.exe/ntkrnlpa.exe : stores kernal image of Windows NT systems &
responsible for various system services such as hardware virtualisation process and memory management, etc.

Here’s how u can get back into your Windows XP.
1. Insert the Windows XP bootable CD into the computer.
2. When prompted to press any key to boot from the CD, press any key.
3. Once in the Windows XP setup menu press the “R” key to repair Windows.
4. Log into your Windows installation by pressing the “1” key and pressing enter.
5. You will then be prompted for your administrator password, enter that password(Usually it is
password,if not set)
6. Copy the below two files to the root directory of the primary hard disk.
The CD-ROM drive letter may be different on your computer.
Here it is “e.”

copy e:\i386\ntldr c:\
copy e:\i386\ntdetect.com c:\

7. Once both of these files have been successfully copied, remove the CD from the computer and reboot.

Working of NTLDR.
When booting NTLDR follows these steps in order:

1. Accesses the file system on the boot drive (either FAT or NT File System, NTFS).
2. If hiberfil.sys is found, and it finds a hibernation image, its contents are loaded into memory and the system resumes where it left off.
3. Otherwise, reads boot.ini and prompts the user with the boot menu accordingly.
4. If a non NT-based OS is selected, then NTLDR loads the associated file listed in boot.ini and gives it control.
5. If an NT-based OS is selected, then NTLDR runs ntdetect.com, which detects the computer’s hardware to load the OS.
6. Starts Ntoskrnl.exe, passing to it the information returned by ntdetect.com.

Animation in Silverlight

Silverlight animation is property-based: The properties
of the elements are modified over an interval of time.

Animation is time-based: The initial state,final state and the
duration is to be set.Silverlight calculates the frame rate.(default 60 frames per second)

Properties in Silverlight have datatypes(double,object,point and color):
Every data type requires a different class of animation

Two strategies for varying a property value in Silverlight animation are:
Linear Interpolation:  Property varies smoothly and continuously over
duration of time.
Keyframe animation:  Properties take many values over duration of time,thus
hopping from one value to another abruptly.

An animation requires:
1) Object
2) A StoryBoard
3) Event Handler

Animations can be started when the page is loaded or can be handled by
event handlers.
1) When page is loaded.
When page is rendered in browser an event trigger attached to page
performs an action of starting the storyboard.
2) When using event handlers
The storyboard is stored as a resource and put into action in response
to any event using code that interacts with the storyboard.

Here are the two examples with the code:

Example1:

simple_animation1 simple_animation_li2

Code1: When page is loaded.

<UserControl.Triggers>
<EventTrigger>
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName=”Box1″ Storyboard.TargetProperty=”Width” From=”100″ To=”400″ Duration=”00:00:10″></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</UserControl.Triggers>

<Grid x:Name=”LayoutRoot” Background=”White”>
<Rectangle Width=”100″ Height=”100″ x:Name=”Box1″>
<Rectangle.Fill>
<SolidColorBrush Color=”CadetBlue”></SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Text=”Rectangle is increasing in width” FontSize=”25″></TextBlock>
</Grid>

Example 2

anim_incode11 anim_incode21

Code 2: Using Event handler

<UserControl.Resources>
<Storyboard x:Name=”animate1″>
<DoubleAnimation Storyboard.TargetName=”Box1″ Storyboard.TargetProperty=”Width” From=”100″ To=”400″ Duration=”00:00:10″></DoubleAnimation>
</Storyboard>

</UserControl.Resources>

<Grid x:Name=”LayoutRoot” Background=”White”>
<Rectangle Width=”100″ Height=”100″ x:Name=”Box1″>
<Rectangle.Fill>
<SolidColorBrush Color=”CadetBlue”></SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Text=”Rectangle is increasing in width on MouseEnter event” FontSize=”20″></TextBlock>
<Button Height=”51″ Margin=”251,0,246,103″ VerticalAlignment=”Bottom” Content=”Start Animation” Click=”Button_Click”/>
</Grid>


Event Handler Code in C# i.e page.xaml.cs file:

private void Button_Click(object sender, RoutedEventArgs e)
{
animate1.Begin();
}


Posted in Uncategorized. 1 Comment »

Layouts in Silverlight

The three important layouts used in Silverlight are:
Grid: Places elements in rows and columns
StackPanel: Stacks its children elements in a single row or column
Canvas: Positions elements using co-ordinates
The figure below shows clear separation between all the layouts.

Layouts in Siverlight

Layouts in Siverlight

Here is the very simple but lengthy code:

<UserControl
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
x:Class=”Layouts_Example.Page”
Width=”800″ Height=”700″ xmlns:d=”http://schemas.microsoft.com/expression/blend/2008&#8243; xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006&#8243; mc:Ignorable=”d”>

<Grid x:Name=”LayoutRoot” Background=”White”>
<Grid Height=”227″ HorizontalAlignment=”Left” Margin=”73,56,0,0″ VerticalAlignment=”Top” Width=”282″ Background=”#FF818040″ ShowGridLines=”True”>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Grid.Row=”0″ Grid.Column=”0″ Height=”50″ Width=”100″ Content=”I am in Grid(0,0)”></Button>
<Button Grid.Row=”1″ Grid.Column=”0″  Height=”50″ Width=”100″ Content=”I am in Grid(1,0)”></Button>
<Button Grid.Row=”0″ Grid.Column=”1″ Height=”50″ Width=”100″ Content=”I am in Grid(0,1)”></Button>
<Button Grid.Row=”1″ Grid.Column=”1″  Height=”50″ Width=”100″ Content=”I am in Grid(1,1)”></Button>
</Grid>

<Canvas Height=”227″ HorizontalAlignment=”Right” Margin=”0,56,73,0″ VerticalAlignment=”Top”       Width=”270″      Background=”#FF5C2459″>
<TextBlock Height=”37″ HorizontalAlignment=”Right” VerticalAlignment=”Top” Width=”136.836″   Text=”Canvas.Top,Canvas.Left” TextWrapping=”Wrap” Canvas.Top=”23″ Canvas.Left=”15″ Foreground=”#FF67F68F”/>
<Ellipse Height=”69″ Width=”99″ Canvas.Left=”154″ Canvas.Top=”25″ Fill=”#FFFFFFFF” Stroke=”#FF000000″/>
<Rectangle Height=”62″ Width=”108″ Canvas.Left=”22″ Canvas.Top=”133″ Fill=”#FF6775CD” Stroke=”#FF000000″/>
</Canvas>
<StackPanel Orientation=”Vertical” Height=”235″ HorizontalAlignment=”Left” Margin=”73,0,0,108″ VerticalAlignment=”Bottom” Width=”282″ Background=”#FF07103C”>
<Button Height=”50″ Width=”200″ Content=”1.No alignment”></Button>
<Button Height=”50″ Width=”200″ Content=”2.Aligned left” HorizontalAlignment=”Left”></Button>
<Button Height=”50″ Width=”200″ Content=”3.Aligned right” HorizontalAlignment=”Right”></Button>
<TextBlock Text=”Orientation=Vertical” Padding=”10″ Foreground=”BlueViolet” FontSize=”18″></TextBlock>
</StackPanel>

<StackPanel  Orientation=”Horizontal” Height=”235″ HorizontalAlignment=”Right” Margin=”0,0,73,108″ VerticalAlignment=”Bottom” Width=”270″ Background=”#FF5E481D”>
<Button Height=”200″ Width=”60″ Content=”1.Bottom” VerticalAlignment=”Bottom”></Button>
<Button Height=”200″ Width=”60″ Content=”2.Top” VerticalAlignment=”Top”></Button>
<Button Height=”200″ Width=”60″ Content=”3.Center” VerticalAlignment=”Center”></Button>
<TextBlock Text=”Orientation Horizontal” Margin=”30″ Foreground=”Wheat” FontSize=”18″>
<TextBlock.RenderTransform>
<RotateTransform Angle=”90″></RotateTransform>
</TextBlock.RenderTransform>
</TextBlock>
</StackPanel>

</Grid>
</UserControl>

Follow

Get every new post delivered to your Inbox.

Join 40 other followers