Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
    Single Page App
    Bootstrap
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> WPF >> WPF (Windows Presentation Foundation) – Introduction and Sample Code in C# .NET
WPF (Windows Presentation Foundation) – Introduction and Sample Code in C# .NET
WPF (Windows Presentation Foundation) – Introduction and Sample Code in C# .NET


by Amit Singh on 9/16/2010 2:26:35 PM

Views: 13090       Comments: 0

WPF (Windows Presentation Foundation) – Introduction and Sample Code in C# .NET

Introduction

Windows Presentation Foundation (WPF) is Microsoft’s latest technology for creating graphical user interfaces, whether they consist of plain forms, document-centric windows, animated cartoons, videos, immersive 3D environments, or all of the above!

 This is a technology that makes it easier than ever to create a broad range of applications.

It removes the limitation of GDI + and User yet provide the kind of productivity that people enjoy with frameworks like window forms.

WPF is a major component of the .NET Framework, starting with version 3.0.

 

FIGURE: The technologies in the .NET Framework 3.0.

The technologies in the .NET Framework 3.0

 

Creating UI using WPF

Developing WPF UI is much more like building web UI than native Windows development. How to define UI in WPF

Defining WPF UI with XAML

XAML (pronounced zammel) is an acronym for eXtensible Application Markup Language and is an XML-based specification for defining UI Although XAML was created specifically for WPF. This is technically called a declarative programming model. WPF will take that definition and convert it into real elements on the screen.

For Example:

//XAML Code

<Page

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

<StackPanel>

<Label>MindStick</Label>

</StackPanel>

</Page>

 

XAML documents are strict XML. Every tag (for example, StackPanel or Label) and attribute (for example, Margin or FontSize) must correspond to a valid .NET type or property. If a tag has the wrong case or an unknown attribute is used, the resulting XAML won’t work.

Defining WPF UI through code

You don’t have to use XAML to define UI elements. You can write code to define your UI, much as you did with Windows Forms. This is the classic imperative programming model. The following code does exactly the same thing as the XAML in above.

For Example:

//Using Code

Window window1;

Page page1;

StackPanel stackPanel1;

Label label1;

 

public Procedural()

{

window1 = new Window();

page1 = new Page();

stackPanel1 = new StackPanel();

label1 = new Label();

label1.Content = "Hello, World!";

stackPanel1.Children.Add(label1);

page1.Content = stackPanel1;

window1.Content = page1;

}

Simple application on WPF

Step1: we open the visual studio and choose the new project as in figure and we select the WPF application and right above corner we check the version 3.5.

 

Select the WPF Application

Select the WPF Application

 

 

WPF Application Form

 

 

Step 2: Adding a button control from toolbox and double click on button and write the code

 

private void button1_Click(object sender, RoutedEventArgs e)

        {

            MessageBox.Show("This is my first wpf application ");           

        }

 

Adding button from toolbox

 

Adding button from toolbox (XAML)

 

Step 3: Running the application

Executed WPF Application

This is the simple demonstration of WPF application

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Amit SinghRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 5070
Advertisement
MindStick SurveyManager
Advertise with Us
  
Copyright © 2009 - 2014MindStick. All Rights Reserved.