SlideShare ist ein Scribd-Unternehmen logo
1 von 73
Downloaden Sie, um offline zu lesen
Windows Presentation
Foundation
Max Knor
Developer Evangelist
Microsoft Austria
http://www.knor.net
Topics

 Overview
 XAML
 Layout Panels
 Controls
 Dependency Objects & Routed Events
 Styles, Templates & Resources
 Data Binding
Demo

WPF Puzzle
Why WPF? Another UI Framework?
 New Display Engine
   Based on Direct3D  no window handles
     Leverages Modern Hardware (GPUs)
     Resolution Independence
     Vectorgraphics  Scalable

 Multimedia Integration
   Controls + Documents + Video/Audio

 New .NET based Development Concept
   New class libraries
   Seperated UI vs. Logic
     XAML – XML based UI Specification language
Developer Designer Collaboration




  Designer                     Developer
Topics

 Overview
 XAML
 Layout Panels
 Controls
 Dependency Objects & Routed Events
 Styles, Templates & Resources
 Data Binding
XAML
 Extensible Application Markup Language

 Generic XML Object Instantiation

 Not How – but What!
   Creates Object Hierarchies


 Used in
   Windows Presentation Foundation
   Windows Workflow Foundation
XAML vs. C#

<Button Background=quot;Redquot;>
     Click Me!
</Button>


Button button1 = new Button();
button1.Content = quot;Click Me!quot;;
button1.Background = new SolidColorBrush(
     Colors.Red);
XAML vs. C#
 XML Namespaces <--> .NET Namespaces

 XML Elements <--> .NET Objects

 XML Attributes <--> .NET Object Properties
Demo

XAML
Topics

 Overview
 XAML
 Layout Panels
 Controls
 Dependency Objects & Routed Events
 Styles, Templates & Resources
 Data Binding
WPF Positioning
 Absolute Positioning
   X / Y, Width / Height


 Relative Positioning
   NO X/Y, Width/Height
   Margin
   Alignment

      <Button Margin=quot;20,10,20,10quot;>Hallo Welt</Button>
WPF Positioning - Alignment
  HorizontalAlignment
       Stretch, Left, Right, Center
  VerticalAlignment
       Stretch, Top, Center, Bottom




 <Button HorizontalAlignment=quot;Stretchquot;   <Button HorizontalAlignment=quot;Leftquot;
          VerticalAlignment=quot;Stretchquot;>            VerticalAlignment=quot;Bottomquot;>
      Hallo Welt                              Hallo Welt
 </Button>                               </Button>
Layout Controls
 StackPanel
   Underneath, side-by-side
 WrapPanel
   Same but with automatic wrapping


 Canvas
   X-,Y- Positions


 DockPanel
 Grid
 ...
Demo

Using Layout Controls
Topics

 Overview
 XAML
 Dependency Objects & Routed Events
 Layout Panels
 Controls
 Styles, Templates & Resources
 Commands
 Data Binding
Class Hierarchy
Simple Controls

• PasswordBox

• ScrollBar

• ProgressBar

• Slider

• TextBox

• RichTextBox
Content Controls
                   ScrollBarViewer
 Button
                   ToolTip
 RepeatButton
 ToggleButton
                   UserControl
                   Window
 CheckBox
                   NavigationWindow
 RadioButton

 Label

 Frame

 ListBoxItem
 StatusBarItem
Demo

Content Controls
Headered Content Controls
 Content Control plus header

   Expander

   MenuItem

   GroupBox

   TabItem

   …
Items Controls
 Container for multiple items (lists)

    ListBox
    ComboBox

    Menu
    ContextMenu
    StatusBar

    TreeView
    TabControl

    ...
Demo

Listbox, Toolbar, Menu
Topics

 Overview
 XAML
 Layout Panels
 Controls
 Dependency Objects & Routed Events
 Styles, Templates & Resources
 Data Binding
Dependency Properties
 Values stored in a central dictionary
   Instead of being stored in a private member


 Can include additional metadata (like default value)

 Manipulated by the WPF runtime
   Databinding
   Animation, Styles, etc…
Dependency Properties
public class MyDependencyObject : DependencyObject
{
  public static readonly DependencyProperty
       SomeStateProperty =
       DependencyProperty.Register(quot;SomeStatequot;,
           typeof(String), typeof(MyDependencyObject));

    public string SomeState
    {
      get { return (string)this.GetValue(SomeStateProperty); }
      set { this.SetValue(SomeStateProperty, value); }
    }
}
Attached Properties

 Store Properties of one control on another
 one

<Grid>
 <Button Grid.Column=“0quot; Grid.Row=quot;40quot;>
  Click Me!
 </Button>
</Grid>
Demo

Dependency Properties
Attached Properties
Routed Events
             Preview   Application

             Preview    Window
 Tunneling




                                     Bubbling
             Preview      Grid

             Preview     Button

             Preview    Canvas

             Preview     Ellipse
Routed Events (Attached Events)

 “Collect” events at a higher hierarchy level


<Canvas Button.Click=“Button_Click”>
 <Button>
  Click Me!
 </Button>
</Canvas>
Events
 Create Routed Events

public static readonly RoutedEvent TapEvent =
          EventManager.RegisterRoutedEvent(
          quot;Tapquot;, RoutingStrategy.Bubble, typeof(RoutedEventHandler),
                   typeof(MyButtonSimple));


                 public event RoutedEventHandler Tap {
                    add { AddHandler(TapEvent, value); }
                    remove { RemoveHandler(TapEvent, value); }
                 }



 Use RoutedEventArgs.Source instead of sender
Demo

Routed Events
Topics

 Overview
 XAML
 Layout Panels
 Controls
 Dependency Objects & Routed Events
 Styles, Templates & Resources
 Data Binding
Designer   Developer
Styles are about
setting properties…
Demo

Basic Styles
Resources
Resource Hierarchy
                                        <Window>
   System Resources                      <Window.Resources>
                                          ...
                                         </Window.Resources>
Application   Application
Resources     Resources                  <Grid>
                                          <Grid.Resources>
                                           ...
   Window/Page     Window/Page
                                          </Grid.Resources>
    Resources       Resources
                                          <ListBox>
 Element               Element             <ListBox.Resources>
Resources             Resources            ...
                                           </ListBox.Resources>
                                          </ListBox>
               Element       Element
                                         </Grid>
              Resources     Resources
                                        </Window>
Automatic Styles/Templates
 Most resources must use x:Key
 Optional with Styles and Data Templates
   Can use TargetType or DataType instead
   Applied to target automatically – no reference required




     <Window.Resources>
      <Style TargetType=quot;{x:Type TextBlock}quot;>
       <Setter Property=quot;Marginquot; Value=quot;5quot; />
      </Style>
     </Window.Resources>
Lookless Controls and Templates
 Control implies behaviour

 Probably supplies default look
   Designer free to supply new look
Demo

Control Templates
Topics

 Overview
 XAML
 Layout Panels
 Controls
 Dependency Objects & Routed Events
 Styles, Templates & Resources
 Data Binding
Data Binding
 Concept




 Binding Source
   On<PropertyName>Changed
   INotificationPropertyChanged
   DependencyProperty
Binding in Markup




<Image Source=quot;truck.pngquot;
                                    <Slider Orientation=
Canvas.Left=
                                      quot;Horizontalquot;
  quot;{Binding Path=Value,
                                     Name=quot;horzPosquot;
      ElementName=horzPos}quot;
                                     Value=quot;40quot;/>
/>


 {Binding Path=Value, ElementName=horzPos}
Demo

UI Element Binding
Object Binding
Share Common Source

                           DataContext=
            StackPanel      {Binding
                              Source={StaticResource myData}}



                   HorizontalSlider
                         Value=
                          {Binding Path=XPos,
                                   Path=XPos}
   Image                    Source={StaticResource myData}}
Canvas.Left=
 {Binding Path=XPos,
          Path=XPos}
   Source={StaticResource myData}}
Provide Data From Code
 May be easier to load data in codebehind
 Can set DataContext in code

  Foo myDataObject = new Foo();
  myDataObject.Bar = 42;

  // Set DataContext
  myWindow.DataContext = myDataObject;
Data Binding – Conversion & Validation




 Validation
   ValidationRule


 Converter
   IValueConverter,
   IMultiValueConverter
Demo

Databinding to CLR Objects
Data and Controls

   ContentControl – singular content
      Button, CheckBox, Label, ListBoxItem, …
   ItemsControl – plural content
      ListBox, ComboBox, Menu, TabControl, ToolBar, …
   Can use data objects as content

myButton.Content = new Car();

                           myListBox.Items.Add(new Car());

              Car c = (Car) myListBox.SelectedItem;
Data Templates

class Car
{
  string Image {get;set}
  string Model {get;set}
}
                             DataTemplate


<DataTemplate x:Key=quot;carTemplatequot;>
 <Border BorderBrush=quot;Bluequot; BorderThickness=quot;2quot; Background=quot;LightGrayquot;
      Margin=quot;10quot; Padding=quot;15,15,15,5quot;>
  <StackPanel>
   <Image HorizontalAlignment=quot;Centerquot; Source=quot;{Binding Path=Image}quot; />
   <Border HorizontalAlignment=quot;Centerquot; BorderBrush=quot;Navyquot;
        Background=quot;#DDFquot; BorderThickness=quot;1quot; Margin=quot;10quot; Padding=quot;3quot;>
     <TextBlock FontSize=quot;18quot; Text=quot;{Binding Path=Model}quot; />
   </Border>
  </StackPanel>
 </Border>
</DataTemplate>
Demo

Databinding a list
Datatemplates
Topics

 Overview
 XAML
 Layout Panels
 Controls
 Dependency Objects & Routed Events
 Styles, Templates & Resources
 Data Binding
Have a look at
 XAML Powertoys
    (http://karlshifflett.wordpress.com/xaml-power-toys/)


 WPF Toolkit – Datagrid, DatePicker, Ribbon
    (www.codeplex.com/wpf/)


 WPF Themes
    (www.codeplex.com/wpfthemes/)


 Silverlight Toolkit
    (www.codeplex.com/silverlight/)
Contact




Max Knor
Developer Evangelist
Microsoft Austria


http://www.knor.net
WPF Commands
WPF Commands
 GOF Command Pattern

 Decoupling control and command

 ICommand interface
   Execute(), CanExecute()
   Implemented by RoutedUICommand


 Source implements ICommandSource
Commands Architecture
Defining Commands
 Controls define a command
 <Button Command=quot;ApplicationCommands.Newquot;>
       <Image Source=quot;toolbargraphics/New.bmpquot; />
 </Button>

 CommandBindings define the handler

<Window.CommandBindings>
  <CommandBinding
      Command=quot;ApplicationCommands.Newquot;
      Executed=quot;FileNewquot;
      CanExecute=quot;CanFileNewquot; />
</Window.CommandBindings>
Command Libraries
 Predefined Command Libraries
   ApplicationCommands
   ComponentCommands
   EditingCommands
   MediaCommands
   NavigationCommand
Demo

CommandBindings
Custom Commands

 Instantiate an RoutedUICommand

 Assign InputGestures

 Pack into CommandLibrary
Demo

Custom Command
Interop and Migration
Interoperability!
 Can use WPF with existing code
   WPF inside existing code
   Existing code inside WPF


 Interop at the component level

 Maximum richness => all WPF
Airspace
One pixel, one technology
 File Edit View Help        File Edit View Help



 Win32       WPF            Win32       WPF



 DirectX                    DirectX
Airspace

File Edit View Help   File Edit View Help

                      Win32
Win32
                         WPF
               WPF

                            DirectX
DirectX
Chrome and Canvas


                     Chrome



                    Canvas
Mixed Application Ideas
 A new look for your chrome
 Visual effects for your canvas
 WPF for faster rendering?
 Wizards and help systems
 Generate HTML => Generate XAML
Windows Forms

private void WindowLoaded(object sender, EventArgs e)
{
   WindowsFormsHost host = new WindowsFormsHost();
   host.Height = new Length(120);
   host.Width = new Length(150);
   swf.Control child = new UserControl1();
   child.Dock = swf.DockStyle.None;
   host.AddChild(child);
   border.Child = host;
}
Demo

WPF <--> Windows Forms Interop
Summary
 Can use WPF with existing code

 Maximum richness => all WPF

 Interop is for components
Wpf Introduction

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event Handling
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Html images syntax
Html images syntaxHtml images syntax
Html images syntax
 
Android Services
Android ServicesAndroid Services
Android Services
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
UDA-Componentes RUP. Reporting
UDA-Componentes RUP. ReportingUDA-Componentes RUP. Reporting
UDA-Componentes RUP. Reporting
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Android application structure
Android application structureAndroid application structure
Android application structure
 
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
 
Android Button
Android ButtonAndroid Button
Android Button
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Angular js PPT
Angular js PPTAngular js PPT
Angular js PPT
 
Vue, vue router, vuex
Vue, vue router, vuexVue, vue router, vuex
Vue, vue router, vuex
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
 

Andere mochten auch

Windows Presentation Foundation
Windows Presentation Foundation  Windows Presentation Foundation
Windows Presentation Foundation Deepika Chaudhary
 
Introduction to XAML and WPF
Introduction to XAML and WPFIntroduction to XAML and WPF
Introduction to XAML and WPFDoncho Minkov
 
Windows presentation foundation
Windows presentation foundationWindows presentation foundation
Windows presentation foundationNaga Harish M
 
WPF For Beginners - Learn in 3 days
WPF For Beginners  - Learn in 3 daysWPF For Beginners  - Learn in 3 days
WPF For Beginners - Learn in 3 daysUdaya Kumar
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentationivpol
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCKhaled Musaied
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial Jm Ramos
 
Integer Review!
Integer Review!Integer Review!
Integer Review!ejboggs
 
08 Testy První Matematické Lekce
08  Testy  První Matematické Lekce08  Testy  První Matematické Lekce
08 Testy První Matematické Lekcejedlickak07
 
Fornitures de rellotges
Fornitures de rellotgesFornitures de rellotges
Fornitures de rellotgesmarblocs
 

Andere mochten auch (20)

An Introduction to WPF
An Introduction to WPFAn Introduction to WPF
An Introduction to WPF
 
Windows Presentation Foundation
Windows Presentation Foundation  Windows Presentation Foundation
Windows Presentation Foundation
 
Introduction to XAML and WPF
Introduction to XAML and WPFIntroduction to XAML and WPF
Introduction to XAML and WPF
 
Windows presentation foundation
Windows presentation foundationWindows presentation foundation
Windows presentation foundation
 
WPF For Beginners - Learn in 3 days
WPF For Beginners  - Learn in 3 daysWPF For Beginners  - Learn in 3 days
WPF For Beginners - Learn in 3 days
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
C#.NET
C#.NETC#.NET
C#.NET
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
WPF - An introduction
WPF - An introductionWPF - An introduction
WPF - An introduction
 
C# basics
 C# basics C# basics
C# basics
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Integer Review!
Integer Review!Integer Review!
Integer Review!
 
Beethoven
BeethovenBeethoven
Beethoven
 
09 FóRky
09  FóRky09  FóRky
09 FóRky
 
Blending In
Blending InBlending In
Blending In
 
Class Act
Class ActClass Act
Class Act
 
she de franco.......bueno bueno y juan pablo
she de franco.......bueno bueno y juan pabloshe de franco.......bueno bueno y juan pablo
she de franco.......bueno bueno y juan pablo
 
08 Testy První Matematické Lekce
08  Testy  První Matematické Lekce08  Testy  První Matematické Lekce
08 Testy První Matematické Lekce
 
Fornitures de rellotges
Fornitures de rellotgesFornitures de rellotges
Fornitures de rellotges
 

Ähnlich wie Wpf Introduction

Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...goodfriday
 
Itemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integrationItemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integration{item:foo}
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2Jim Driscoll
 
WPF & Silverlight UI
WPF & Silverlight UIWPF & Silverlight UI
WPF & Silverlight UIDave Allen
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and DashboardsAtlassian
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulationborkweb
 
Create a mobile web app with Sencha Touch
Create a mobile web app with Sencha TouchCreate a mobile web app with Sencha Touch
Create a mobile web app with Sencha TouchJames Pearce
 
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
 
Complex Data Binding
Complex Data BindingComplex Data Binding
Complex Data BindingDoncho Minkov
 
A mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesA mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesJames Pearce
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology updateDoug Domeny
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQueryAlan Hecht
 

Ähnlich wie Wpf Introduction (20)

Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
 
Itemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integrationItemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integration
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
 
java ee 6 Petcatalog
java ee 6 Petcatalogjava ee 6 Petcatalog
java ee 6 Petcatalog
 
WPF & Silverlight UI
WPF & Silverlight UIWPF & Silverlight UI
WPF & Silverlight UI
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and Dashboards
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
JavaEE Spring Seam
JavaEE Spring SeamJavaEE Spring Seam
JavaEE Spring Seam
 
WPF Fundamentals
WPF FundamentalsWPF Fundamentals
WPF Fundamentals
 
WPF and Databases
WPF and DatabasesWPF and Databases
WPF and Databases
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
Widget Tutorial
Widget TutorialWidget Tutorial
Widget Tutorial
 
Create a mobile web app with Sencha Touch
Create a mobile web app with Sencha TouchCreate a mobile web app with Sencha Touch
Create a mobile web app with Sencha Touch
 
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
 
Complex Data Binding
Complex Data BindingComplex Data Binding
Complex Data Binding
 
A mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesA mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutes
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology update
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
Struts2
Struts2Struts2
Struts2
 
Vb.Net Web Forms
Vb.Net  Web FormsVb.Net  Web Forms
Vb.Net Web Forms
 

Mehr von Martha Rotter

EdTech 2012 Keynote: Digital Literacy - Your Message is Your Medium
EdTech 2012 Keynote: Digital Literacy - Your Message is Your MediumEdTech 2012 Keynote: Digital Literacy - Your Message is Your Medium
EdTech 2012 Keynote: Digital Literacy - Your Message is Your MediumMartha Rotter
 
Curing Your Skin With Food
Curing Your Skin With FoodCuring Your Skin With Food
Curing Your Skin With FoodMartha Rotter
 
Designing Narrative Content Workshop
Designing Narrative Content WorkshopDesigning Narrative Content Workshop
Designing Narrative Content WorkshopMartha Rotter
 
Introducing the Windows Phone Application Platform
Introducing the Windows Phone Application PlatformIntroducing the Windows Phone Application Platform
Introducing the Windows Phone Application PlatformMartha Rotter
 
OMG TMI!!!!!!!!111111111111111
OMG TMI!!!!!!!!111111111111111OMG TMI!!!!!!!!111111111111111
OMG TMI!!!!!!!!111111111111111Martha Rotter
 
Building Multi-Touch Experiences
Building Multi-Touch ExperiencesBuilding Multi-Touch Experiences
Building Multi-Touch ExperiencesMartha Rotter
 
Sketch Flow Overview
Sketch Flow OverviewSketch Flow Overview
Sketch Flow OverviewMartha Rotter
 
Creating Video Games From Scratch Sky Con
Creating Video Games From Scratch Sky ConCreating Video Games From Scratch Sky Con
Creating Video Games From Scratch Sky ConMartha Rotter
 
Client Continuum Dec Fy09
Client Continuum Dec Fy09Client Continuum Dec Fy09
Client Continuum Dec Fy09Martha Rotter
 
Silverlight Ux Talk External
Silverlight Ux Talk ExternalSilverlight Ux Talk External
Silverlight Ux Talk ExternalMartha Rotter
 
Podcasting Inside the Evil Empire
Podcasting Inside the Evil EmpirePodcasting Inside the Evil Empire
Podcasting Inside the Evil EmpireMartha Rotter
 
Silverlight For Students
Silverlight For StudentsSilverlight For Students
Silverlight For StudentsMartha Rotter
 
Silverlight2 Deepdive Mix08 External
Silverlight2 Deepdive Mix08 ExternalSilverlight2 Deepdive Mix08 External
Silverlight2 Deepdive Mix08 ExternalMartha Rotter
 
Ruby & Python with Silverlight O RLY? YA RLY!
Ruby & Python with Silverlight O RLY? YA RLY!Ruby & Python with Silverlight O RLY? YA RLY!
Ruby & Python with Silverlight O RLY? YA RLY!Martha Rotter
 

Mehr von Martha Rotter (16)

EdTech 2012 Keynote: Digital Literacy - Your Message is Your Medium
EdTech 2012 Keynote: Digital Literacy - Your Message is Your MediumEdTech 2012 Keynote: Digital Literacy - Your Message is Your Medium
EdTech 2012 Keynote: Digital Literacy - Your Message is Your Medium
 
Beware the Shiny!
Beware the Shiny!Beware the Shiny!
Beware the Shiny!
 
Curing Your Skin With Food
Curing Your Skin With FoodCuring Your Skin With Food
Curing Your Skin With Food
 
Designing Narrative Content Workshop
Designing Narrative Content WorkshopDesigning Narrative Content Workshop
Designing Narrative Content Workshop
 
Introducing the Windows Phone Application Platform
Introducing the Windows Phone Application PlatformIntroducing the Windows Phone Application Platform
Introducing the Windows Phone Application Platform
 
OMG TMI!!!!!!!!111111111111111
OMG TMI!!!!!!!!111111111111111OMG TMI!!!!!!!!111111111111111
OMG TMI!!!!!!!!111111111111111
 
Building Multi-Touch Experiences
Building Multi-Touch ExperiencesBuilding Multi-Touch Experiences
Building Multi-Touch Experiences
 
Sketch Flow Overview
Sketch Flow OverviewSketch Flow Overview
Sketch Flow Overview
 
Creating Video Games From Scratch Sky Con
Creating Video Games From Scratch Sky ConCreating Video Games From Scratch Sky Con
Creating Video Games From Scratch Sky Con
 
Composite WPF
Composite WPFComposite WPF
Composite WPF
 
Client Continuum Dec Fy09
Client Continuum Dec Fy09Client Continuum Dec Fy09
Client Continuum Dec Fy09
 
Silverlight Ux Talk External
Silverlight Ux Talk ExternalSilverlight Ux Talk External
Silverlight Ux Talk External
 
Podcasting Inside the Evil Empire
Podcasting Inside the Evil EmpirePodcasting Inside the Evil Empire
Podcasting Inside the Evil Empire
 
Silverlight For Students
Silverlight For StudentsSilverlight For Students
Silverlight For Students
 
Silverlight2 Deepdive Mix08 External
Silverlight2 Deepdive Mix08 ExternalSilverlight2 Deepdive Mix08 External
Silverlight2 Deepdive Mix08 External
 
Ruby & Python with Silverlight O RLY? YA RLY!
Ruby & Python with Silverlight O RLY? YA RLY!Ruby & Python with Silverlight O RLY? YA RLY!
Ruby & Python with Silverlight O RLY? YA RLY!
 

Kürzlich hochgeladen

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Kürzlich hochgeladen (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Wpf Introduction

  • 1. Windows Presentation Foundation Max Knor Developer Evangelist Microsoft Austria http://www.knor.net
  • 2. Topics Overview XAML Layout Panels Controls Dependency Objects & Routed Events Styles, Templates & Resources Data Binding
  • 4. Why WPF? Another UI Framework? New Display Engine Based on Direct3D  no window handles Leverages Modern Hardware (GPUs) Resolution Independence Vectorgraphics  Scalable Multimedia Integration Controls + Documents + Video/Audio New .NET based Development Concept New class libraries Seperated UI vs. Logic XAML – XML based UI Specification language
  • 5. Developer Designer Collaboration Designer Developer
  • 6. Topics Overview XAML Layout Panels Controls Dependency Objects & Routed Events Styles, Templates & Resources Data Binding
  • 7. XAML Extensible Application Markup Language Generic XML Object Instantiation Not How – but What! Creates Object Hierarchies Used in Windows Presentation Foundation Windows Workflow Foundation
  • 8. XAML vs. C# <Button Background=quot;Redquot;> Click Me! </Button> Button button1 = new Button(); button1.Content = quot;Click Me!quot;; button1.Background = new SolidColorBrush( Colors.Red);
  • 9. XAML vs. C# XML Namespaces <--> .NET Namespaces XML Elements <--> .NET Objects XML Attributes <--> .NET Object Properties
  • 11. Topics Overview XAML Layout Panels Controls Dependency Objects & Routed Events Styles, Templates & Resources Data Binding
  • 12. WPF Positioning Absolute Positioning X / Y, Width / Height Relative Positioning NO X/Y, Width/Height Margin Alignment <Button Margin=quot;20,10,20,10quot;>Hallo Welt</Button>
  • 13. WPF Positioning - Alignment HorizontalAlignment Stretch, Left, Right, Center VerticalAlignment Stretch, Top, Center, Bottom <Button HorizontalAlignment=quot;Stretchquot; <Button HorizontalAlignment=quot;Leftquot; VerticalAlignment=quot;Stretchquot;> VerticalAlignment=quot;Bottomquot;> Hallo Welt Hallo Welt </Button> </Button>
  • 14. Layout Controls StackPanel Underneath, side-by-side WrapPanel Same but with automatic wrapping Canvas X-,Y- Positions DockPanel Grid ...
  • 16. Topics Overview XAML Dependency Objects & Routed Events Layout Panels Controls Styles, Templates & Resources Commands Data Binding
  • 18. Simple Controls • PasswordBox • ScrollBar • ProgressBar • Slider • TextBox • RichTextBox
  • 19. Content Controls ScrollBarViewer Button ToolTip RepeatButton ToggleButton UserControl Window CheckBox NavigationWindow RadioButton Label Frame ListBoxItem StatusBarItem
  • 21. Headered Content Controls Content Control plus header Expander MenuItem GroupBox TabItem …
  • 22. Items Controls Container for multiple items (lists) ListBox ComboBox Menu ContextMenu StatusBar TreeView TabControl ...
  • 24. Topics Overview XAML Layout Panels Controls Dependency Objects & Routed Events Styles, Templates & Resources Data Binding
  • 25. Dependency Properties Values stored in a central dictionary Instead of being stored in a private member Can include additional metadata (like default value) Manipulated by the WPF runtime Databinding Animation, Styles, etc…
  • 26. Dependency Properties public class MyDependencyObject : DependencyObject { public static readonly DependencyProperty SomeStateProperty = DependencyProperty.Register(quot;SomeStatequot;, typeof(String), typeof(MyDependencyObject)); public string SomeState { get { return (string)this.GetValue(SomeStateProperty); } set { this.SetValue(SomeStateProperty, value); } } }
  • 27. Attached Properties Store Properties of one control on another one <Grid> <Button Grid.Column=“0quot; Grid.Row=quot;40quot;> Click Me! </Button> </Grid>
  • 29. Routed Events Preview Application Preview Window Tunneling Bubbling Preview Grid Preview Button Preview Canvas Preview Ellipse
  • 30. Routed Events (Attached Events) “Collect” events at a higher hierarchy level <Canvas Button.Click=“Button_Click”> <Button> Click Me! </Button> </Canvas>
  • 31. Events Create Routed Events public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent( quot;Tapquot;, RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyButtonSimple)); public event RoutedEventHandler Tap { add { AddHandler(TapEvent, value); } remove { RemoveHandler(TapEvent, value); } } Use RoutedEventArgs.Source instead of sender
  • 33. Topics Overview XAML Layout Panels Controls Dependency Objects & Routed Events Styles, Templates & Resources Data Binding
  • 34. Designer Developer
  • 35. Styles are about setting properties…
  • 37. Resource Hierarchy <Window> System Resources <Window.Resources> ... </Window.Resources> Application Application Resources Resources <Grid> <Grid.Resources> ... Window/Page Window/Page </Grid.Resources> Resources Resources <ListBox> Element Element <ListBox.Resources> Resources Resources ... </ListBox.Resources> </ListBox> Element Element </Grid> Resources Resources </Window>
  • 38. Automatic Styles/Templates Most resources must use x:Key Optional with Styles and Data Templates Can use TargetType or DataType instead Applied to target automatically – no reference required <Window.Resources> <Style TargetType=quot;{x:Type TextBlock}quot;> <Setter Property=quot;Marginquot; Value=quot;5quot; /> </Style> </Window.Resources>
  • 39. Lookless Controls and Templates Control implies behaviour Probably supplies default look Designer free to supply new look
  • 41. Topics Overview XAML Layout Panels Controls Dependency Objects & Routed Events Styles, Templates & Resources Data Binding
  • 42. Data Binding Concept Binding Source On<PropertyName>Changed INotificationPropertyChanged DependencyProperty
  • 43. Binding in Markup <Image Source=quot;truck.pngquot; <Slider Orientation= Canvas.Left= quot;Horizontalquot; quot;{Binding Path=Value, Name=quot;horzPosquot; ElementName=horzPos}quot; Value=quot;40quot;/> /> {Binding Path=Value, ElementName=horzPos}
  • 45. Share Common Source DataContext= StackPanel {Binding Source={StaticResource myData}} HorizontalSlider Value= {Binding Path=XPos, Path=XPos} Image Source={StaticResource myData}} Canvas.Left= {Binding Path=XPos, Path=XPos} Source={StaticResource myData}}
  • 46. Provide Data From Code May be easier to load data in codebehind Can set DataContext in code Foo myDataObject = new Foo(); myDataObject.Bar = 42; // Set DataContext myWindow.DataContext = myDataObject;
  • 47. Data Binding – Conversion & Validation Validation ValidationRule Converter IValueConverter, IMultiValueConverter
  • 49. Data and Controls ContentControl – singular content Button, CheckBox, Label, ListBoxItem, … ItemsControl – plural content ListBox, ComboBox, Menu, TabControl, ToolBar, … Can use data objects as content myButton.Content = new Car(); myListBox.Items.Add(new Car()); Car c = (Car) myListBox.SelectedItem;
  • 50. Data Templates class Car { string Image {get;set} string Model {get;set} } DataTemplate <DataTemplate x:Key=quot;carTemplatequot;> <Border BorderBrush=quot;Bluequot; BorderThickness=quot;2quot; Background=quot;LightGrayquot; Margin=quot;10quot; Padding=quot;15,15,15,5quot;> <StackPanel> <Image HorizontalAlignment=quot;Centerquot; Source=quot;{Binding Path=Image}quot; /> <Border HorizontalAlignment=quot;Centerquot; BorderBrush=quot;Navyquot; Background=quot;#DDFquot; BorderThickness=quot;1quot; Margin=quot;10quot; Padding=quot;3quot;> <TextBlock FontSize=quot;18quot; Text=quot;{Binding Path=Model}quot; /> </Border> </StackPanel> </Border> </DataTemplate>
  • 52. Topics Overview XAML Layout Panels Controls Dependency Objects & Routed Events Styles, Templates & Resources Data Binding
  • 53. Have a look at XAML Powertoys (http://karlshifflett.wordpress.com/xaml-power-toys/) WPF Toolkit – Datagrid, DatePicker, Ribbon (www.codeplex.com/wpf/) WPF Themes (www.codeplex.com/wpfthemes/) Silverlight Toolkit (www.codeplex.com/silverlight/)
  • 54. Contact Max Knor Developer Evangelist Microsoft Austria http://www.knor.net
  • 55.
  • 57. WPF Commands GOF Command Pattern Decoupling control and command ICommand interface Execute(), CanExecute() Implemented by RoutedUICommand Source implements ICommandSource
  • 59. Defining Commands Controls define a command <Button Command=quot;ApplicationCommands.Newquot;> <Image Source=quot;toolbargraphics/New.bmpquot; /> </Button> CommandBindings define the handler <Window.CommandBindings> <CommandBinding Command=quot;ApplicationCommands.Newquot; Executed=quot;FileNewquot; CanExecute=quot;CanFileNewquot; /> </Window.CommandBindings>
  • 60. Command Libraries Predefined Command Libraries ApplicationCommands ComponentCommands EditingCommands MediaCommands NavigationCommand
  • 62. Custom Commands Instantiate an RoutedUICommand Assign InputGestures Pack into CommandLibrary
  • 65. Interoperability! Can use WPF with existing code WPF inside existing code Existing code inside WPF Interop at the component level Maximum richness => all WPF
  • 66. Airspace One pixel, one technology File Edit View Help File Edit View Help Win32 WPF Win32 WPF DirectX DirectX
  • 67. Airspace File Edit View Help File Edit View Help Win32 Win32 WPF WPF DirectX DirectX
  • 68. Chrome and Canvas Chrome Canvas
  • 69. Mixed Application Ideas A new look for your chrome Visual effects for your canvas WPF for faster rendering? Wizards and help systems Generate HTML => Generate XAML
  • 70. Windows Forms private void WindowLoaded(object sender, EventArgs e) { WindowsFormsHost host = new WindowsFormsHost(); host.Height = new Length(120); host.Width = new Length(150); swf.Control child = new UserControl1(); child.Dock = swf.DockStyle.None; host.AddChild(child); border.Child = host; }
  • 71. Demo WPF <--> Windows Forms Interop
  • 72. Summary Can use WPF with existing code Maximum richness => all WPF Interop is for components