Sunday, January 15, 2012

WPF Overview (XAML)

This topic describes the features of the XAML language and demonstrates how you can use XAML to write Windows Presentation Foundation (WPF) with Example.

What is XAML in WPF?
XAML is Extensible Application Markup Language. As applied to the .NET Framework programming model, XAML simplifies creating a UI for a .NET Framework application. You can create visible UI elements in the declarative XAML markup, and then separate the UI definition from the run-time logic by using code-behind files, joined to the markup through partial class definitions. XAML directly represents the instantiation of objects in a specific set of backing types defined in assemblies. This is unlike most other markup languages, which are typically an interpreted language without such a direct tie to a backing type system. XAML enables a workflow where separate parties can work on the UI and the logic of an application, using potentially different tools.
When represented as text, XAML files are XML files that generally have the .xaml extension. The files can be encoded by any XML encoding, but encoding as UTF-8 is typical.

New in XAML of .NET 4.0 :
1.    Easy Object References with {x:Reference}
2.    Built-in Types
3.    Generics in XAML with {x:TypeArguments}
4.    Support for Arbitrary Dictionary Keys  
5.    Use of Non-Default Constructors with {x:Arguments}
6.    Use of Static Factory Methods with{ x:FactoryMethod}

1: Easy Object References with {x:Reference}
<Label Target="{Binding ElementName=firstName}">FirstName</Label>
<TextBox x:Name="firstName" />

<Label Target="{x:Reference firstName}">FirstName</Label>
<TextBox x:Name="firstName" />

2: Built-in Types
    <x:String> </x:String>
    <x:Object ><x:Object/>
    <x:Dictionary> <x:Dictionary/>

3: Generics in XAML with {x:TypeArguments}

<ObservableCollection x:TypeArguments="Employee">
    <l:Employee FirstName="John" Name="Doe" />
    <l:Employee FirstName="Tim" Name="Smith" />
</ObservableCollection />
4: Support for Arbitrary Dictionary Keys:

<StreamGeometry>M 0 0 L 12 8 l 9 12 z
5: Use of Non-Default Constructors with {x:Arguments}

6: Use of Static Factory Methods with{ x:FactoryMethod}

               <Guid x:FactoryMethod="Guid.NewGuid" />
Controls in WPF
7.LivePreview ComboBox

1: ItemsControl
     <ListBox l:ItemsControlHelper.ScrollToLastItem="true" />
2: Calendar
<Calendar SelectionMode="{Binding SelectedItem,ElementName=selectionmode}">
        <CalendarDateRange Start="01/01/2010" End="01/06/2010" />
        <CalendarDateRange Start="05/01/2010" End="05/03/2010" />
3: ToolTips
<Button Content="Submit">
                <TextBlock FontWeight="Bold">Submit!!</TextBlock>
                <TextBlock>Submits the request to the server!</TextBlock>
4: Expander
<Expander Header="More Options">
    <StackPanel Margin="5,4,0,0">
        <CheckBox Margin="3" Content="Option 1" />
        <CheckBox Margin="3" Content="Option 2" />
        <CheckBox Margin="3" Content="Option 3" />
5: TextBox
        <TextBox SpellCheck.IsEnabled="True" Language="Hindi" />

6: DataGrid
        <DataGrid ItemsSource="{Binding Customers}" 
          SelectionMode="Extended" SelectionUnit="Cell" />

7: LivePreview ComboBox
        <TextBlock Text="Preview Value:" />
        <TextBlock Text="{Binding LivePreviewItem, ElementName=liveBox}" />
        <l:LivePreviewComboBox x:Name="liveBox"/>
8: ContextMenu
            <MenuItem Command="Cut">
                    <Image Source="Images/cut.png" />
            <MenuItem Command="Copy">
                    <Image Source="Images/copy.png" />
            <MenuItem Command="Paste">
                    <Image Source="Images/paste.png" />
9: Menus        
<Menu IsMainMenu="True">
    <MenuItem Header="File" />
    <MenuItem Header="Edit" />
    <MenuItem Header="View" />
    <MenuItem Header="Window" />
    <MenuItem Header="Help" />
10: PasswordBox
      <Label Content="Password:" />
      <PasswordBox x:Name="passwordBox" Width="130" />
11: Dialogs
        <Button Content="Cancel" IsCancel="True" />
        <Button Click="OkClick" Content="Ok!!" IsDefault="true" />
12: Slider
<Slider Minimum="0 Maximum="20" IsSnapToTickEnabled="True"
13: RadioButton
    <RadioButton GroupName="Os" Content="Windows XP" IsChecked="True"/>
    <RadioButton GroupName="Os" Content="Windows Vista" />
    <RadioButton GroupName="Os" Content="Windows 7" />
    <RadioButton GroupName="Office" Content="Microsoft Office 2003"/>
    <RadioButton GroupName="Office" Content="Open Office"/>
14: Popup
<Popup StaysOpen="False" />
15: ListBox
<ListBox Margin="40">

16: ListView
                   <Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>
17: TextBlock
        <TextBlock Text="This is a multiline text!!" 
           LineHeight="25" LineStackingStrategy="BlockLineHeight" />

Data Binding control

1.Debug DataBinding Issues
2.Data Viewing, Sorting and Filtering  
3.Data Binding Overview
4.Popular Data Binding Expressions
5.How to Bind EnumValues
6.Value Converters
7.Data Validation
8.Elegant way for INotifyPropertyChanged

Visit on more details INotifyPropertyChanged:

1.Introduction to WPF Layout
2.Grid Panel
3.Canvas Panel
5.Dock Panel
7.Wrap Panel

1: Introduction to WPF Layout
2: Grid Panel
3: Canvas Panel
4: StackPanel
5: Dock Panel
6: ViewBox   
      7: Wrap Panel 

2.Mutli Touch