Shalvin Interests

Monday, December 13, 2010

WPF Console

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;

namespace WpfBlankProjShalvin
{
    class Class1 : Window 
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new Class1 { Title = "Shalvin", WindowStartupLocation = WindowStartupLocation.CenterScreen, Width = 300, Height = 200  });
        }
    }
}



WPF StackPanel and Button Click

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;

using System.Windows.Controls;

namespace WpfApplication1
{
    class Class1 : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new Class1());
        }

        StackPanel stp;

        Button btn;
        public Class1()
    {
 stp = new StackPanel();
 this.Content = stp;

 btn = new Button { Content = "Shalvin" };
            btn.Click += new RoutedEventHandler(btn_Click);
 stp.Children.Add(btn);

    }


        private void btn_Click(Object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Hello");
        }
    }
}



Grid RowDefinition

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;

using System.Windows.Controls;

namespace WpfGrid
{
    class Class1 : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new Class1());
        }

        Grid grd;

        TextBlock tbl;
        RowDefinition rd;
        
        public Class1()
        {
            grd = new Grid { ShowGridLines = true };
            this.Content = grd;
            rd = new RowDefinition ();
            grd.RowDefinitions.Add(rd);
            
            rd = new RowDefinition();
            grd.RowDefinitions.Add(rd);

            tbl = new TextBlock { Text = "Name" };
            grd.Children.Add(tbl);
        }

    }
}

Friday, December 10, 2010

WPF and XAML Introduction

WPF is the new generation Presentation API from Microsoft.
XML Application Markup Language abbreviated as XAML is the markup language used from specifying the user interface aspects of WPF. Infact XAML is not limited to WPF. Technologies like Silverlight, Windows Phone 7 uses XAML.

<Window x:Class="WpfBasicsShalvin.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="Shalvin" Height="350" Width="525">

    <Grid>

       

    </Grid>

</Window>


Button

<Window x:Class="WpfBasicsShalvin.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Shalvin" Height="350" Width="525">
    <Grid>
        <Button Width="75" Height="50" Width="75" >Shalvin P D</Button>
    </Grid>
</Window>

StackPanel

<Window x:Class="WpfBasicsShalvin.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Shalvin" Height="350" Width="525">
    <Grid>
        <StackPanel>
            <TextBox Name="txtName" Width="75"/>
            <Button Width="75" Height="50" >Shalvin P D</Button>
        </StackPanel>
    </Grid>
</Window>


Grid
<Window x:Class="WpfBasicsShalvin.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Shalvin" Height="800" Width="600" Loaded="Window_Loaded">
    <Grid ShowGridLines="True">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="75"/>
            <ColumnDefinition Width="100"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>

        <TextBlock>Name</TextBlock>
        <TextBox Name="txtName" Width="75" Grid.Column="1"/>
    </Grid>
</Window>


ListBox

<Window x:Class="WpfBasicsShalvin.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Shalvin" Height="800" Width="600" Loaded="Window_Loaded">
    <Grid ShowGridLines="True">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="75"/>
            <ColumnDefinition Width="100"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>

        <TextBlock>Name</TextBlock>
        <TextBox Name="txtName" Width="75" Grid.Column="1"/>

        <TextBlock Grid.Row="2">Students</TextBlock>
        <ListBox Grid.Row="3" Grid.Column="1" Name="lstStudents" />
    </Grid>
</Window>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfBasicsShalvin
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lstStudents.Items.Add("Shalvin");
            lstStudents.Items.Add("Anson");
            lstStudents.Items.Add("Glitcy");    }
    }
}


ComboBox
<Window x:Class="WpfBasicsShalvin.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Shalvin" Height="800" Width="600" Loaded="Window_Loaded">
    <Grid ShowGridLines="True">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="75"/>
            <ColumnDefinition Width="100"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="100"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>

        </Grid.RowDefinitions>

        <TextBlock>Name</TextBlock>
        <TextBox Name="txtName" Width="75" Grid.Column="1"/>

        <TextBlock Grid.Row="2">Students</TextBlock>
        <ListBox Grid.Row="3" Grid.Column="1" Name="lstStudents" />

        <TextBlock Grid.Row="6">Students</TextBlock>
        <ComboBox Height="30" Grid.Row="7" Grid.Column="1" Name="cboBlogs" />


    </Grid>
</Window>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfBasicsShalvin
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        List<string> lstrBlogs = new List<string> { "ShalvinPD.blogspot.com", "shalvininterests.blogspot.com", "shalvinmusic.blogspot.com" };

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lstStudents.Items.Add("Shalvin");
            lstStudents.Items.Add("Anson");
            lstStudents.Items.Add("Glitcy");

            cboBlogs.ItemsSource = lstrBlogs;
        }
    }
}



Menu

<Window x:Class="WPF_Menu_Shalvin.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Shalvin P D Menu" Height="350" Width="525">
    <Grid>
        <Menu Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="menu1" VerticalAlignment="Top" Width="200">
            <MenuItem Name="mnuIndia" Header="India">
                <MenuItem Name="mnuKerala" Header="Kerala">
                    <MenuItem Name="mnuKochi" Click="mnuKochi_Click"     Header="Kochi" />
                    <MenuItem Name="mnuTrivandrum" Click="mnuTrivandrum_Click" Header="Trivandrum" />
                </MenuItem>
                <MenuItem Name="mnuKarnataka" Header="Karnataka">
                    <MenuItem Name="mnuBangalor" Header="Bangalore"/>
                </MenuItem>
                
            </MenuItem>
            
            <MenuItem Name="mnuUSA" Header="USA">
                <MenuItem Name="mnuWashington" Header="Washington">
                    <MenuItem Name="Seattle" Header="Seattle" Click="Seattle_Click"/>
                </MenuItem>
            </MenuItem>
        </Menu>
    </Grid>
</Window>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPF_Menu_Shalvin
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void mnuKochi_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Industrial capital of Kerala, fastest growing third tier city in India");

        }

        private void mnuTrivandrum_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Capital of Kerala");
        }

        private void Seattle_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Head quarters of Microsoft");
        }
    }
}