Posts tagged StartWith WPF


Layout and Controls in WPF


Half of the battle can be won through UI and Control placement in software paradigm .All of us know the a good UI leaves extraordinary impact on user so this post is all about control placing and control layout in WPF.In this post we will cover following topics.

  1. Layout
  2. Classic Controls

Layout in WPF are versatile than win form controls.In Win form most of the frequently used layouts used the coordinate based control placement while in WPF it is slot based depending on the screen space.the most common used layouts in wpf are as follows :

  • Canvas
  • Used Coordinate based Control Layout (Same as panel in normal Win Form)
  • Stack Layout
  • Control are placed horizontally / Vertically one above the other
  • Wrap Layout
  • Controls are  placed sequentially horizontally / vertically
  • Grid Layout
  • Creates column,Row based grid and each cell allows controls to be placed
  • Dock Panel
  • Docks the control on specified area

    A collected sample of all can be seen bellow


    More details can be found

    Classic Controls

    The control set in WPF is rich with wide support for data binding .A full comparison of WPF and winform control can be found from here.


    Additional Link for Controls


    Getting Into WPF


    Learning a new programming platform is never easy until unless somebody is really inspired.WPF (Windows Presentation Foundation ) is  quite convincing if you look at its prospective and the capability it gives to user.This new graphical subsystem from Microsoft relies on Direct X for rendering instead of GDI.So the advantage this  declarative programming model is Resolution Independent provides extensive integration with independent technology (Text to speech , 3d animation ,video etc),Hardware acceleration with Direct 3d and most useful complete customization of controls.

    Wpf applications development  can be of two type

    • Windows Based Application
    • Browser Based Application (XBAP)
    1285599500_package_edutainment What is Declarative Programming ?

    This Blog post is about my experience with first WPF application , a simple application with basic understanding.

    Create a WPF Project :

    Open Visual Studio and Select WPF Application .Provide a Name “StartWithWpf” and click Ok .

    Create a WPF Project

    Have a look at the source folder , It contains a default MainWindows.xaml and App.xaml.So the XAML Markup drives WPF application with similar syntax of XML (Read More about XAML and Syntax) .A complied form of XAML is known as BAML.

    r.2625741350 App.Xaml
    • App.xaml is a class(Singleton Pattern) which encapsulate the application specific functionality and resource handling such as
      • Application Lifetime
      • Application Windows,property
      • Resource Management
      • Command Line Parameter
      • Navigation
    Digging Into APP.Xaml:

    The App.Xaml (Application class )is the entry point for the application .We can write as code behind application class or in the mark-up.The declarative Mark-up is must for XBAP.

    Code Snippet

    1. <Application
    2. xmlns=””
    3. xmlns:x=””
    4. x:Class=”StartWithWpf.App”
    5. StartupUri=”MainWindow.xaml”>
    6. </Application>

    So the app.xaml need above lines to run a project.These are the Attributes of Application .

    xmlns –:Defines the Namespace for the Application

    xmlns : x-:Defines the additional namespace for the application

    Basics of XAML Syntax

    Above both attributes direct to the specification required to be referenced for xaml.You can find out some additional references as you add your some custom namespaces.

    Custom Namespace in WPF

    Adding a Form:

    Now lets add a Form , here it is Windows (instead of Form as in WinApp).So adding a Window named “MyFirstWindow”.Add new WPF Window

    Now the look at the Window , we have added.

    Wpf Window

    I will change the Title property and add a label to the Grid Layout.(Layouts are very important in WPF ).

    Code Snippet
    1. <Window x:Class=”StartWithWpf.MyFirstWindow”
    2. xmlns=””
    3. xmlns:x=””
    4. Title=”Home” Height=”300″ Width=”300″
    5. >
    6. <Grid>
    7. <Label> My First WPF Application </Label>
    8. </Grid>
    9. </Window>

    Now to Run the application i will go to App.xaml and Change the StartUpUri attribute to “MyFirstWindow.xaml”.Lets run it and you are ready with your first WPF application.A simple but fair start  :) .

    Go to Top