SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Presented by G. Sharada
Who is this training for?
 If you have relevant experience in building UI with
 either WinForms or ASP.NET controls

 If you have been coding in C# (or VB.NET) for
 sometime now.

 If you want to learn WPF
What I intend to do.
 Present WPF in ways that you learn it by doing, rather
 than just reading about it.

 Introduce you to the new buzz-words around WPF –
 so you can google them later.
What I don’t intend to do.
 Advocate WPF over Windows Forms


 Pretend to be an authority on WPF
Agenda
      Overview              • 25 minutes

    Introduction to XAML    • 15 minutes

    Screen layouts in WPF   • 20 minutes

    Working with controls   • 30 minutes

         Applying styles    • 15 minutes

     Managing resources     • 15 minutes

          WPF Lab #1
             Q&A
WPF - Overview
 A new Windows UI Framework
 Declarative programming model – XAML
 State of the art graphics
    DirectX under the covers
    2D, 3D graphics
 Not tied to hardware - logical pixels
 Raised abstraction level
    Data Contexts
    Resources
Will Microsoft dump WinForms?
         No, WinForms is here to stay.

         WPF is not intended to replace
          WinForms.

         Microsoft will continue to enhance and
          support WinForms for years to come.

         We have high interoperability between
          WinForms and WPF.
Issues with WPF
 Learning curve can be a bit steep


 Its easier to find WinForms developers then WPF
 developers

 Comparatively, WinForms has much larger online
 resources and developer community support.
So, is WPF worth it all?
WPF Pros
 Superior Data Binding
 Clean separation between UI and business logic
 Easy UI extensibility through Data/Control
  templates/Attached behaviors
 Powerful support for styles and themes
 In-built UI virtualization
 Can incorporate various media types, videos,
  documents, 3D content, or dynamically load portions
  of a user interface from web
XAML
 It stands for “Extensible Application Markup
 Language”

 It is an XML-based language for creating and
 initializing .NET objects.

 It is used by WPF to determine where all of the
 controls and other UI elements go
Declaring a Window in XAML
<Window x:Class="LameApplications.Sample1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Button
            x:Name="btn"
            Width="200"
            Height="25"
            Click="btn_Click">Click me, baby, one more time!</Button>
    </Grid>
</Window>
XAML – Markup Extensions
 Markup extensions add special processing to XAML
  attribute values.

 For example, this:
  <TextBox Text="{Binding Path=Name}" />


  is just a shortcut for this –
   <TextBox.Text>
     <Binding Path="Name" />
   </TextBox.Text>
Layouts in WPF
 A layout panel is a control that knows how to arrange its
  content.
 A conversation takes place between the layout container
  and its children. (in two stages referred to as passes.)
Layout Panels - Canvas



<Canvas>
  <Rectangle Canvas.Left="40" Canvas.Top="31" Width="63" Height="41"
        Fill="Blue" />
  <Ellipse Canvas.Left="130" Canvas.Top="79" Width="58" Height="58"
        Fill="Blue" />
  <Path Canvas.Left="61" Canvas.Top="28" Width="133" Height="98"
        Fill="Blue" Stretch="Fill" Data="M61,125 L193,28"/>
</Canvas>
Layout Panels - DockPanel



<DockPanel LastChildFill="True">
        <Button Content="Dock=Top" DockPanel.Dock="Top"/>
        <Button Content="Dock=Bottom" DockPanel.Dock="Bottom"/>
        <Button Content="Dock=Left"/>
        <Button Content="Dock=Right" DockPanel.Dock="Right"/>
        <Button Content="LastChildFill=True"/>
</DockPanel>
Layout Panels - Grid
<Grid>
          <Grid.RowDefinitions>
                  <RowDefinition />
                  <RowDefinition />
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
                  <ColumnDefinition />
                  <ColumnDefinition />
          </Grid.ColumnDefinitions>
           <Button Grid.Row="0"
                  Grid.Column="0"
                  Grid.ColumnSpan="2">A</Button>
          <Button Grid.Row="0“
                  Grid.Column="2">C</Button>
          <Button Grid.Row="1" Grid.Column="0"
                  Grid.RowSpan="2">D</Button>
</Grid>
Layout Panels - StackPanel




<StackPanel>
        <TextBlock Margin="10" FontSize="20">How do you like your
                coffee?</TextBlock>
        <Button Margin="10">Black</Button>
        <Button Margin="10">With milk</Button>
        <Button Margin="10">Latte machiato</Button>
        <Button Margin="10">Chappuchino</Button>
</StackPanel>
Layout Panels - WrapPanel




<WrapPanel Orientation="Horizontal">
        <Button Content="Button" />
        <Button Content="Button" />
        <Button Content="Button" />
        <Button Content="Button" />
</WrapPanel>
WPF Control Tree
Control
A second look
Types of controls
 ContentControl - is a control that has an
  additional Content property. This is often used for simple
  containers. Example: Window

 HeaderedContentControl - is a control that has
  an Content and a Header property. This is used for controls with
  a header like TabControl.

 ItemsControl - a control that has an
  additional Items collection. This is a good choice for controls
  that display a dynamic list of items without selection.

 Selector - an ItemsControl whose items can be indexed and
  selected. This is used for ListBox, ComboBox.
Control Template
 Modify the visual appearance of a control, while
  maintaining the behavior

<Button Margin="0,0,2,2" Grid.Row="0"
  Grid.Column="0" Name="cell00">
  <Button.Template>
      <ControlTemplate>
            <Grid>
                  <Rectangle />
            </Grid>
      </ControlTemplate>
  </Button.Template>
</Button>
Content Presenter
 WPF equivalent of “your content here”

<ControlTemplate TargetType="{x:Type Button}">
   <Border Background="{TemplateBinding
       Property=Background}">
       <ContentPresenter />
   </Border>
</ControlTemplate>
Styles
 A set of properties applied to content used for visual
  rendering
 The ability to apply different visual effects based on
  user events
 A collection property setter elements
Inline Styles
Set style property inline using standard XAML property
  element syntax

<Button Name="cell00">
  <Button.Style>
    <Style>
       <Setter Property="Button.FontSize"
              Value="32pt" />
       <Setter Property="Button.FontWeight"
              Value="Bold" />
    </Style>
  </Button.Style>
</Button>
Named Styles
 Apply style using key
<Window ...>
   <Window.Resources>
        <Style x:Key="CellTextStyle">
                <Setter Property="Control.FontSize"
                       Value="32pt" />
                <Setter Property="Control.FontWeight"
                       Value="Bold" />
        </Style>
   </Window.Resources>
  <Button Style="{StaticResource CellTextStyle}” Name="cell00" />
</Window>
Target typed Styles
 With key
<Style x:Key="CellTextStyle" TargetType="{x:Type Button}">
  <Setter Property="FontSize" Value="32pt" />
  <Setter Property="FontWeight" Value="Bold" />
</Style>


 Without key (is applied to all controls of target-type)
<Style TargetType="{x:Type Button}">
  <Setter Property="FontSize" Value="32pt" />
  <Setter Property="FontWeight" Value="Bold" />
</Style>
Extending Styles
 Extend a style by adding new properties, or overriding
  existing properties

<Style x:Key="CellTextStyle">
  <Setter Property="Control.FontSize" Value="32pt" />
  <Setter Property="Control.FontWeight" Value="Bold" />
</Style>

<Style x:Key="StatusTextStyle" BasedOn="{StaticResource
  CellTextStyle}">
  <Setter Property="TextBlock.FontWeight" Value=“Bold" />
  <Setter Property="TextBlock.Foreground" Value="White" />
</Style>
Style Triggers
 Triggers are a way to wrap one or more Setter elements in a
  condition

 Simplest form of a trigger is a PropertyTrigger

<Style TargetType="{x:Type Button}">
  <Style.Triggers>
      <Trigger Property="Content" Value="{x:Null}" >
            <Setter Property="ToolTip" Value="click
                   to move here" />
      </Trigger>
  </Style.Triggers>
</Style>
Resources in WPF
 Centralizing information regarding
    Styles
    Fonts
    data sources
    Images
    Dlls
 Static resource - One time lookup of a resource entry
 Dynamic resource - Auto updating lookup of a
 resource entry
Scope
 Scope of a resource is limited to its parent

   Application level (global to whole application)
   Window level (specific to window)
   User control level
   Control level
WPF - An introduction

Weitere ähnliche Inhalte

Was ist angesagt?

Windows Presentation Foundation
Windows Presentation Foundation  Windows Presentation Foundation
Windows Presentation Foundation Deepika Chaudhary
 
Windows presentation foundation
Windows presentation foundationWindows presentation foundation
Windows presentation foundationNaga Harish M
 
MSDN Unleashed: WPF Demystified
MSDN Unleashed: WPF DemystifiedMSDN Unleashed: WPF Demystified
MSDN Unleashed: WPF DemystifiedDave Bost
 
Windows Presentation Foundation & XAML
Windows Presentation Foundation & XAMLWindows Presentation Foundation & XAML
Windows Presentation Foundation & XAMLAlex Sooraj
 
Windows Presentation Foundation
Windows Presentation FoundationWindows Presentation Foundation
Windows Presentation FoundationTran Ngoc Son
 
WPF - the future of GUI is near
WPF - the future of GUI is nearWPF - the future of GUI is near
WPF - the future of GUI is nearBartlomiej Filipek
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningSyed Irtaza Ali
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labelsRuss Weakley
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchRuss Weakley
 
The Audio User Experience for Widgets
The Audio User Experience for WidgetsThe Audio User Experience for Widgets
The Audio User Experience for Widgetstoddkloots
 
A Designer's Overview of Windows Presentation Foundation
A Designer's Overview of Windows Presentation FoundationA Designer's Overview of Windows Presentation Foundation
A Designer's Overview of Windows Presentation Foundationgoodfriday
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsManuel Lemos
 
Cape Town MS Developer User Group: Xamarin Community Toolkit
Cape Town MS Developer User Group: Xamarin Community ToolkitCape Town MS Developer User Group: Xamarin Community Toolkit
Cape Town MS Developer User Group: Xamarin Community ToolkitJavier Suárez Ruiz
 
Accessible custom radio buttons and checkboxes
Accessible custom radio buttons and checkboxesAccessible custom radio buttons and checkboxes
Accessible custom radio buttons and checkboxesRuss Weakley
 
Leveraging the Ribbon API and Dialog Framework
Leveraging the Ribbon API and Dialog FrameworkLeveraging the Ribbon API and Dialog Framework
Leveraging the Ribbon API and Dialog FrameworkCory Peters
 
JavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and LibrariesJavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and LibrariesOleksii Prohonnyi
 
Advisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptAdvisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptdominion
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NETPeter Gfader
 

Was ist angesagt? (20)

Windows Presentation Foundation
Windows Presentation Foundation  Windows Presentation Foundation
Windows Presentation Foundation
 
WPF
WPFWPF
WPF
 
Windows presentation foundation
Windows presentation foundationWindows presentation foundation
Windows presentation foundation
 
MSDN Unleashed: WPF Demystified
MSDN Unleashed: WPF DemystifiedMSDN Unleashed: WPF Demystified
MSDN Unleashed: WPF Demystified
 
Windows Presentation Foundation & XAML
Windows Presentation Foundation & XAMLWindows Presentation Foundation & XAML
Windows Presentation Foundation & XAML
 
Windows Presentation Foundation
Windows Presentation FoundationWindows Presentation Foundation
Windows Presentation Foundation
 
An Overview Of Wpf
An Overview Of WpfAn Overview Of Wpf
An Overview Of Wpf
 
WPF - the future of GUI is near
WPF - the future of GUI is nearWPF - the future of GUI is near
WPF - the future of GUI is near
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labels
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off Switch
 
The Audio User Experience for Widgets
The Audio User Experience for WidgetsThe Audio User Experience for Widgets
The Audio User Experience for Widgets
 
A Designer's Overview of Windows Presentation Foundation
A Designer's Overview of Windows Presentation FoundationA Designer's Overview of Windows Presentation Foundation
A Designer's Overview of Windows Presentation Foundation
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced Plugins
 
Cape Town MS Developer User Group: Xamarin Community Toolkit
Cape Town MS Developer User Group: Xamarin Community ToolkitCape Town MS Developer User Group: Xamarin Community Toolkit
Cape Town MS Developer User Group: Xamarin Community Toolkit
 
Accessible custom radio buttons and checkboxes
Accessible custom radio buttons and checkboxesAccessible custom radio buttons and checkboxes
Accessible custom radio buttons and checkboxes
 
Leveraging the Ribbon API and Dialog Framework
Leveraging the Ribbon API and Dialog FrameworkLeveraging the Ribbon API and Dialog Framework
Leveraging the Ribbon API and Dialog Framework
 
JavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and LibrariesJavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and Libraries
 
Advisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptAdvisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScript
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NET
 

Andere mochten auch (20)

An Introduction to WPF
An Introduction to WPFAn Introduction to WPF
An Introduction to WPF
 
State management
State managementState management
State management
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
WCF
WCFWCF
WCF
 
ASP.NET Lecture 3
ASP.NET Lecture 3ASP.NET Lecture 3
ASP.NET Lecture 3
 
Master page in ASP . NET
Master page in ASP . NETMaster page in ASP . NET
Master page in ASP . NET
 
State management
State managementState management
State management
 
Master pages ppt
Master pages pptMaster pages ppt
Master pages ppt
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
 
Master pages
Master pagesMaster pages
Master pages
 
State management in ASP.NET
State management in ASP.NETState management in ASP.NET
State management in ASP.NET
 
WCF tutorial
WCF tutorialWCF tutorial
WCF tutorial
 
JSP Standart Tag Lİbrary - JSTL
JSP Standart Tag Lİbrary - JSTLJSP Standart Tag Lİbrary - JSTL
JSP Standart Tag Lİbrary - JSTL
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag Library
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
Webservices
WebservicesWebservices
Webservices
 
C#.NET
C#.NETC#.NET
C#.NET
 
Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 

Ähnlich wie WPF - An introduction

WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesWPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesMohammad Shaker
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & AnimationNguyen Tuan
 
Building appsinsilverlight4 part_1
Building appsinsilverlight4 part_1Building appsinsilverlight4 part_1
Building appsinsilverlight4 part_1Dennis Perlot
 
Create Responsive Website Design with Bootstrap 3
Create Responsive Website Design with Bootstrap 3Create Responsive Website Design with Bootstrap 3
Create Responsive Website Design with Bootstrap 3Wahyu Putra
 
Controls Use in Windows Presentation Foundation (WPF)
Controls Use in Windows Presentation Foundation (WPF)Controls Use in Windows Presentation Foundation (WPF)
Controls Use in Windows Presentation Foundation (WPF)iFour Technolab Pvt. Ltd.
 
Grasping The LightSwitch Paradigm
Grasping The LightSwitch ParadigmGrasping The LightSwitch Paradigm
Grasping The LightSwitch ParadigmAndrew Brust
 
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8netmind
 
Bootstrap PPT by Mukesh
Bootstrap PPT by MukeshBootstrap PPT by Mukesh
Bootstrap PPT by MukeshMukesh Kumar
 
AMP for JavaScripters
AMP for JavaScriptersAMP for JavaScripters
AMP for JavaScriptersFelix Arntz
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and ImprovedTimothy Fisher
 
20150728 100분만에 배우는 windows 10 앱 개발
20150728 100분만에 배우는 windows 10 앱 개발20150728 100분만에 배우는 windows 10 앱 개발
20150728 100분만에 배우는 windows 10 앱 개발영욱 김
 
Overview of WPF in light of Ribbon UI Control
Overview of WPF in light of Ribbon UI ControlOverview of WPF in light of Ribbon UI Control
Overview of WPF in light of Ribbon UI ControlAbhishek Sur
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckAnthony Montalbano
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface
 
Getting to Know Bootstrap for Rapid Web Development
Getting to Know Bootstrap for Rapid Web DevelopmentGetting to Know Bootstrap for Rapid Web Development
Getting to Know Bootstrap for Rapid Web DevelopmentLaurence Svekis ✔
 

Ähnlich wie WPF - An introduction (20)

WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesWPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and Templates
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation
 
Xaml programming
Xaml programmingXaml programming
Xaml programming
 
Building appsinsilverlight4 part_1
Building appsinsilverlight4 part_1Building appsinsilverlight4 part_1
Building appsinsilverlight4 part_1
 
Create Responsive Website Design with Bootstrap 3
Create Responsive Website Design with Bootstrap 3Create Responsive Website Design with Bootstrap 3
Create Responsive Website Design with Bootstrap 3
 
Controls Use in Windows Presentation Foundation (WPF)
Controls Use in Windows Presentation Foundation (WPF)Controls Use in Windows Presentation Foundation (WPF)
Controls Use in Windows Presentation Foundation (WPF)
 
Grasping The LightSwitch Paradigm
Grasping The LightSwitch ParadigmGrasping The LightSwitch Paradigm
Grasping The LightSwitch Paradigm
 
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
 
Bootstrap PPT by Mukesh
Bootstrap PPT by MukeshBootstrap PPT by Mukesh
Bootstrap PPT by Mukesh
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
 
AMP for JavaScripters
AMP for JavaScriptersAMP for JavaScripters
AMP for JavaScripters
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
Chpater1
Chpater1Chpater1
Chpater1
 
20150728 100분만에 배우는 windows 10 앱 개발
20150728 100분만에 배우는 windows 10 앱 개발20150728 100분만에 배우는 windows 10 앱 개발
20150728 100분만에 배우는 windows 10 앱 개발
 
Overview of WPF in light of Ribbon UI Control
Overview of WPF in light of Ribbon UI ControlOverview of WPF in light of Ribbon UI Control
Overview of WPF in light of Ribbon UI Control
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages Suck
 
HTML5
HTML5 HTML5
HTML5
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
 
Getting to Know Bootstrap for Rapid Web Development
Getting to Know Bootstrap for Rapid Web DevelopmentGetting to Know Bootstrap for Rapid Web Development
Getting to Know Bootstrap for Rapid Web Development
 

WPF - An introduction

  • 1. Presented by G. Sharada
  • 2. Who is this training for?  If you have relevant experience in building UI with either WinForms or ASP.NET controls  If you have been coding in C# (or VB.NET) for sometime now.  If you want to learn WPF
  • 3. What I intend to do.  Present WPF in ways that you learn it by doing, rather than just reading about it.  Introduce you to the new buzz-words around WPF – so you can google them later.
  • 4. What I don’t intend to do.  Advocate WPF over Windows Forms  Pretend to be an authority on WPF
  • 5. Agenda Overview • 25 minutes Introduction to XAML • 15 minutes Screen layouts in WPF • 20 minutes Working with controls • 30 minutes Applying styles • 15 minutes Managing resources • 15 minutes WPF Lab #1 Q&A
  • 6.
  • 7. WPF - Overview  A new Windows UI Framework  Declarative programming model – XAML  State of the art graphics  DirectX under the covers  2D, 3D graphics  Not tied to hardware - logical pixels  Raised abstraction level  Data Contexts  Resources
  • 8. Will Microsoft dump WinForms?  No, WinForms is here to stay.  WPF is not intended to replace WinForms.  Microsoft will continue to enhance and support WinForms for years to come.  We have high interoperability between WinForms and WPF.
  • 9. Issues with WPF  Learning curve can be a bit steep  Its easier to find WinForms developers then WPF developers  Comparatively, WinForms has much larger online resources and developer community support.
  • 10. So, is WPF worth it all?
  • 11. WPF Pros  Superior Data Binding  Clean separation between UI and business logic  Easy UI extensibility through Data/Control templates/Attached behaviors  Powerful support for styles and themes  In-built UI virtualization  Can incorporate various media types, videos, documents, 3D content, or dynamically load portions of a user interface from web
  • 12.
  • 13. XAML  It stands for “Extensible Application Markup Language”  It is an XML-based language for creating and initializing .NET objects.  It is used by WPF to determine where all of the controls and other UI elements go
  • 14. Declaring a Window in XAML <Window x:Class="LameApplications.Sample1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> <Button x:Name="btn" Width="200" Height="25" Click="btn_Click">Click me, baby, one more time!</Button> </Grid> </Window>
  • 15. XAML – Markup Extensions  Markup extensions add special processing to XAML attribute values.  For example, this: <TextBox Text="{Binding Path=Name}" /> is just a shortcut for this – <TextBox.Text> <Binding Path="Name" /> </TextBox.Text>
  • 16.
  • 17. Layouts in WPF  A layout panel is a control that knows how to arrange its content.  A conversation takes place between the layout container and its children. (in two stages referred to as passes.)
  • 18. Layout Panels - Canvas <Canvas> <Rectangle Canvas.Left="40" Canvas.Top="31" Width="63" Height="41" Fill="Blue" /> <Ellipse Canvas.Left="130" Canvas.Top="79" Width="58" Height="58" Fill="Blue" /> <Path Canvas.Left="61" Canvas.Top="28" Width="133" Height="98" Fill="Blue" Stretch="Fill" Data="M61,125 L193,28"/> </Canvas>
  • 19. Layout Panels - DockPanel <DockPanel LastChildFill="True"> <Button Content="Dock=Top" DockPanel.Dock="Top"/> <Button Content="Dock=Bottom" DockPanel.Dock="Bottom"/> <Button Content="Dock=Left"/> <Button Content="Dock=Right" DockPanel.Dock="Right"/> <Button Content="LastChildFill=True"/> </DockPanel>
  • 20. Layout Panels - Grid <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Button Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">A</Button> <Button Grid.Row="0“ Grid.Column="2">C</Button> <Button Grid.Row="1" Grid.Column="0" Grid.RowSpan="2">D</Button> </Grid>
  • 21. Layout Panels - StackPanel <StackPanel> <TextBlock Margin="10" FontSize="20">How do you like your coffee?</TextBlock> <Button Margin="10">Black</Button> <Button Margin="10">With milk</Button> <Button Margin="10">Latte machiato</Button> <Button Margin="10">Chappuchino</Button> </StackPanel>
  • 22. Layout Panels - WrapPanel <WrapPanel Orientation="Horizontal"> <Button Content="Button" /> <Button Content="Button" /> <Button Content="Button" /> <Button Content="Button" /> </WrapPanel>
  • 23.
  • 27. Types of controls  ContentControl - is a control that has an additional Content property. This is often used for simple containers. Example: Window  HeaderedContentControl - is a control that has an Content and a Header property. This is used for controls with a header like TabControl.  ItemsControl - a control that has an additional Items collection. This is a good choice for controls that display a dynamic list of items without selection.  Selector - an ItemsControl whose items can be indexed and selected. This is used for ListBox, ComboBox.
  • 28. Control Template  Modify the visual appearance of a control, while maintaining the behavior <Button Margin="0,0,2,2" Grid.Row="0" Grid.Column="0" Name="cell00"> <Button.Template> <ControlTemplate> <Grid> <Rectangle /> </Grid> </ControlTemplate> </Button.Template> </Button>
  • 29. Content Presenter  WPF equivalent of “your content here” <ControlTemplate TargetType="{x:Type Button}"> <Border Background="{TemplateBinding Property=Background}"> <ContentPresenter /> </Border> </ControlTemplate>
  • 30.
  • 31. Styles  A set of properties applied to content used for visual rendering  The ability to apply different visual effects based on user events  A collection property setter elements
  • 32. Inline Styles Set style property inline using standard XAML property element syntax <Button Name="cell00"> <Button.Style> <Style> <Setter Property="Button.FontSize" Value="32pt" /> <Setter Property="Button.FontWeight" Value="Bold" /> </Style> </Button.Style> </Button>
  • 33. Named Styles  Apply style using key <Window ...> <Window.Resources> <Style x:Key="CellTextStyle"> <Setter Property="Control.FontSize" Value="32pt" /> <Setter Property="Control.FontWeight" Value="Bold" /> </Style> </Window.Resources> <Button Style="{StaticResource CellTextStyle}” Name="cell00" /> </Window>
  • 34. Target typed Styles  With key <Style x:Key="CellTextStyle" TargetType="{x:Type Button}"> <Setter Property="FontSize" Value="32pt" /> <Setter Property="FontWeight" Value="Bold" /> </Style>  Without key (is applied to all controls of target-type) <Style TargetType="{x:Type Button}"> <Setter Property="FontSize" Value="32pt" /> <Setter Property="FontWeight" Value="Bold" /> </Style>
  • 35. Extending Styles  Extend a style by adding new properties, or overriding existing properties <Style x:Key="CellTextStyle"> <Setter Property="Control.FontSize" Value="32pt" /> <Setter Property="Control.FontWeight" Value="Bold" /> </Style> <Style x:Key="StatusTextStyle" BasedOn="{StaticResource CellTextStyle}"> <Setter Property="TextBlock.FontWeight" Value=“Bold" /> <Setter Property="TextBlock.Foreground" Value="White" /> </Style>
  • 36. Style Triggers  Triggers are a way to wrap one or more Setter elements in a condition  Simplest form of a trigger is a PropertyTrigger <Style TargetType="{x:Type Button}"> <Style.Triggers> <Trigger Property="Content" Value="{x:Null}" > <Setter Property="ToolTip" Value="click to move here" /> </Trigger> </Style.Triggers> </Style>
  • 37.
  • 38. Resources in WPF  Centralizing information regarding  Styles  Fonts  data sources  Images  Dlls  Static resource - One time lookup of a resource entry  Dynamic resource - Auto updating lookup of a resource entry
  • 39. Scope  Scope of a resource is limited to its parent  Application level (global to whole application)  Window level (specific to window)  User control level  Control level

Hinweis der Redaktion

  1. Hi everybody.. Welcome to the very first session in our WPF/WCF Training series.I am G. Sharada, I will be your presenter for today’s session. Normally at this point I conduct an introduction round – but as we have a lot to cover in the next 2 hrs; so we are going to just skip it for now and have it during the Q&amp;A round. Moving on…
  2. Just to line-out a few pre-requisites – The assumption here is that you have at least some level of experience with UI building and developing custom controls. It could be anything from WinForms, ASP.NET, or even HTML DOM. You of course have to be well-versed with C# This one’s really important. Because, WPF’s got a steep learning curve, and you really have to dedicate some time and effort here to master it.
  3. Would like to state my intensions hereBasically, what I really want to do here is present wpf in we would be actually building an entire sample application while going through each topic in our agenda-Secondly, with the limited time we have, I will be floating around a lot of keywords that will prove useful in your research and study for WPF
  4. What I really won’t be doing is advocate WPF over WinForms. We will be discussing about this topic in the coming slides. Also, WPF is a vast powerful technology and I am still having my fun exploring it; It’s a continuous process. So, lets make this a mutual learning experience for all of us.
  5. Our agenda for this session. After a brief overview about WPF – we will jump right into coding XAML, building controls, creating screen layouts, styling and all.While doing that we will be building a application alongside. So, you can see the theory in action. Once we are done with all of that - there will be a Q&amp;A round wherein I will try my best to answer your queries.
  6. So what WPF really is?Its Microsoft’s latest generation platform for building visual applicationsIt has XML declared layout – i.e. XAML A totally new system for controls, 2D-3D graphics, animations Get the benefits of hardware acceleration for smoother graphics and all around better performance This is due to work being offloaded to graphics processing units [GPUs] instead of central processor units [CPUs]).There’s separation between the control logic and data/business logic
  7. Order of the elements is important here.
  8. Order of the elements is important here.
  9. Order of the elements is important here.
  10. Order of the elements is important here.