Search Chirayu Software Solutions Blog

Friday, August 31, 2012

Intoduction of silverlight

What is silverlight ?

Silverlight is a web based technology, launched by Microsoft in April 2007. Silverlight is considered as a competitor to Adobes Flash.

Silverlight applications are delivered to browsers in a text-based markup language called XAML. One important difference between Flash and XAML is, Flash is a compiled application where as XAML is text based. Search engines can analyze and index such content, which is a huge benefit for webmasters.

For regular internet users, Silverlight is a browser plug-in that supports video, audio and animations.

For web developers, Silverlight offers much more. Silverlight supports video and audio files without need of much programming. It allows them to handle events from web pages (like handle start/end of video playing etc)


Tools required to develop Silverlight applications

.
To run Silverlight applcations in a web browser, you need to have Silverlight run time installed on the client browser as a plug in. This is a light weight version of .NET runtime.

However, to develop a Silverlight application, you need something more.

Silverlight SDK

This include a set of tools required to compile and build Silverlight controls.


  If you are using Visual Studio, you can download the Silverlight development tools from here. This download include the Service pack1 for VS.NET and the Silverlight SDK.

Tuesday, August 28, 2012

WCF - Windows Communication Foundation


Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data. A few sample scenarios include:
  • A secure service to process business transactions.
  • A service that supplies current data to others, such as a traffic report or other monitoring service.
  • A chat service that allows two people to communicate or exchange data in real time.
  • A dashboard application that polls one or more services for data and presents it in a logical presentation.
  • Exposing a workflow implemented using Windows Workflow Foundation as a WCF service.
  • A Silverlight application to poll a service for the latest data feeds.

Monday, August 27, 2012

Color Animation in WPF


CODE:
<Rectangle Name="myrect" Width="350" Height="250">
            <Rectangle.Fill>
                <SolidColorBrush x:Name="brush" Color="Red"/>
            </Rectangle.Fill>
            <Rectangle.Triggers>
                <EventTrigger RoutedEvent="Window.Loaded">
                    <BeginStoryboard>
                        <Storyboard RepeatBehavior="Forever">
                            <ColorAnimation Storyboard.TargetName="brush"
                      Storyboard.TargetProperty="Color" From="Red" To="Green"
                      Duration="0:0:1" BeginTime="0:0:0"/>
                            <ColorAnimation Storyboard.TargetName="brush"
                      Storyboard.TargetProperty="Color" From="Green" To="Blue"
                      Duration="0:0:1" BeginTime="0:0:1"/>
                            <ColorAnimation Storyboard.TargetName="brush"
                      Storyboard.TargetProperty="Color" From="Blue" To="Yellow"
                      Duration="0:0:1" BeginTime="0:0:2"/>
                            <ColorAnimation Storyboard.TargetName="brush"
                      Storyboard.TargetProperty="Color" From="Yellow"
                      To="Red" Duration="0:0:1" BeginTime="0:0:3"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Rectangle.Triggers>
        </Rectangle>



The above code produces the following output:

Double Animation in WPF


WPF achieves animation by animating element properties. For example, if you want to produce a zoom in or zoom out effect for a rectangle, you can animate the width and height properties. The following code animates a rectangle by modifying its width and height properties.

CODE:

<Window x:Class="WpfApplication1.doubleanimation"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="doubleanimation" Height="300" Width="300">
    <Grid>
        <Rectangle Name="myrect" Width="1" Height="1">
            <Rectangle.Fill>
                <SolidColorBrush Color="Red"/>
            </Rectangle.Fill>
            <Rectangle.Triggers>
                <EventTrigger RoutedEvent="Window.Loaded">
                    <BeginStoryboard>
                        <Storyboard RepeatBehavior="Forever">
                            <DoubleAnimation Storyboard.TargetName="myrect"
                       Storyboard.TargetProperty="Width" From="1" To="350"
                       Duration="0:0:1" BeginTime="0:0:0"/>
                            <DoubleAnimation Storyboard.TargetName="myrect"
                       Storyboard.TargetProperty="Height" From="1" To="250"
                       Duration="0:0:1" BeginTime="0:0:1"/>
                            <DoubleAnimation Storyboard.TargetName="myrect"
                       Storyboard.TargetProperty="Height" From="250"
                       To="1" Duration="0:0:1" BeginTime="0:0:2"/>
                            <DoubleAnimation Storyboard.TargetName="myrect"
                       Storyboard.TargetProperty="Width" From="350" To="1"
                       Duration="0:0:1" BeginTime="0:0:3"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Rectangle.Triggers>
        </Rectangle>
    </Grid>
</Window>


Following is the output of the above code:

EXPLANATION:

This code triggers the animation automatically when the window is loaded. The code adds an EventTrigger to the rectangle. The BeginStoryboard action runs a storyboard. This storyboard uses fourDoubleAnimations. The first DoubleAnimation increases the width of the rectangle from 1 to 350. The second one increases the height from 1 to 250. The third and fourth do the reverse by decreasing the height and width back to 1. The four DoubleAnimations are made to run in a sequence by setting the BeginTimeattribute such that each animation starts when the previous is over. The RepeatBehavior attribute of the Storyboard is assigned the value "Forever" which makes the animation run indefinitely. 

Binding Data to Data Grid in WPF

In this post we are going to learn how to bind data to DataGrid in WPF(Windows Presentation Foundation)  
Create new project named as DataGridSample 
  



To show a basic data grid, just drop a DataGrid control to your view and bind the ItemsSource to a data table
The DataGrid provides a feature called AutoGenerateColumns that automatically generates column according to the columns of your data datatable. It generates the following types of columns:
  • TextBox columns for string values
  • CheckBox columns for boolean values
  • ComboBox columns for enumerable values
  • Hyperlink columns for Uri values
MainWindow.xaml
<Grid>
      <DataGrid AutoGenerateColumns="True" Height="225" HorizontalAlignment="Left"Margin="28,21,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="408" />
</Grid>
MainWindow.xaml.cs
        SqlConnection cn = new SqlConnection("Data     Source=.;database=Practice;trusted_connection=true");
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            cn.Open();
            SqlDataAdapter da = new SqlDataAdapter("Select * from Employee", cn);
            DataSet ds = new DataSet();
            da.Fill(ds, "Employee");
            dataGrid1.ItemsSource = ds.Tables["Employee"].DefaultView;
        }
Result Window


Alternatively you can define your columns manually by setting the AutoGenerateColumnsproperty to False. 
Here we can add following type of columns 
DataGridCheckBoxColumn
DataGridComboBoxColumn
DataGridHyperlinkColumn               
DataGridTemplateColumn
DataGridTextColumn
MainWindow.xaml
<DataGrid AutoGenerateColumns="False" Height="173" HorizontalAlignment="Left"Margin="12,12,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="292" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding EmpId}" Header="Id" />
<DataGridTextColumn Binding="{Binding EmpName}" Header="Name" />
<DataGridTextColumn Binding="{Binding Designation}"    Header="Designation" />
<DataGridTextColumn Binding="{Binding Location}" Header="Location" />
<DataGridCheckBoxColumn Binding="{Binding IsActive}" Header="IsActive" />
 </DataGrid.Columns>
 </DataGrid>


Result Window

Linq Example

 protected void Page_Load(object sender, EventArgs e)
    {
        List<Books> books = Books.GetBooks();

        var booktitles = from b in books select b.Title;

        foreach (var title in booktitles)
            lblbooks.Text += String.Format("{0} <br />", title);
      IEnumerable<Books> books = Books.GetBooks();
      IEnumerable<Salesdetails> sales =
                         Salesdetails.getsalesdetails();
       var booktitles = from b in books
                      join s in sales
                     on b.ID equals s.ID
                   select new { Name = b.Title, Pages = s.pages, Sales = s.sales };
       foreach (var title in booktitles)
          lblbooks.Text += String.Format("{0} <br />", title);
      GridView1.DataSource = booktitles;
        GridView1.DataBind();
    }
    public class Books
    {
        public string ID { get; set; }
        public string Title { get; set; }
        public decimal Price { get; set; }
        public DateTime DateOfRelease { get; set; }

        public static List<Books> GetBooks()
        {
            List<Books> list = new List<Books>();
         
            list.Add(new Books
            {
                ID = "001",
                Title = "Programming in C#",
                Price = 634.76m,
                DateOfRelease = Convert.ToDateTime("2010-02-05")
            });

            list.Add(new Books
            {
                ID = "002",
                Title = "Learn Jave in 30 days",
                Price = 250.76m,
                DateOfRelease = Convert.ToDateTime("2011-08-15")
            });

            list.Add(new Books
            {
                ID = "003",
                Title = "Programming in ASP.Net 4.0",
                Price = 700.00m,
                DateOfRelease = Convert.ToDateTime("2011-02-05")
            });

            list.Add(new Books
            {
                ID = "004",
                Title = "VB.Net Made Easy",
                Price = 500.99m,
                DateOfRelease = Convert.ToDateTime("2011-12-31")
            });

            list.Add(new Books
            {
                ID = "005",
                Title = "Programming in C",
                Price = 314.76m,
                DateOfRelease = Convert.ToDateTime("2010-02-05")
            });

            list.Add(new Books
            {
                ID = "006",
                Title = "Programming in C++",
                Price = 456.76m,
                DateOfRelease = Convert.ToDateTime("2010-02-05")
            });

            list.Add(new Books
            {
                ID = "007",
                Title = "Datebase Developement",
                Price = 1000.76m,
                DateOfRelease = Convert.ToDateTime("2010-02-05")
            });
            return list;
        }
    }
        public class Salesdetails
        {
            public int sales { get; set; }
            public int pages { get; set; }
            public string ID { get; set; }

            public static IEnumerable<Salesdetails> getsalesdetails()
            {
                Salesdetails[] sd =
      {
      new Salesdetails { ID = "001", pages=678, sales = 110000},
      new Salesdetails { ID = "002", pages=789, sales = 60000},
      new Salesdetails { ID = "003", pages=456, sales = 40000},
      new Salesdetails { ID = "004", pages=900, sales = 80000},
      new Salesdetails { ID = "005", pages=456, sales = 90000},
      new Salesdetails { ID = "006", pages=870, sales = 50000},
      new Salesdetails { ID = "007", pages=675, sales = 40000},
      };
                return sd.OfType<Salesdetails>();
            }
        }