.NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown...

29
.NET Framework 3.0 - Presentation

Transcript of .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown...

Page 1: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

.NET Framework 3.0 - Presentation

Page 2: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

About Me

• Patrik Löwendahl– C# MVP– Certified Vista Touchdown Trainer– Instructor @ Cornerstone– Blog @ www.lowendahl.net

• Cornerstone– Swedens largest CPLS– 4 Course centers, Stockholm, Malmoe,

Gothenburg, Sundsvall.

Page 3: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Agenda

• WPF Solutions

• WPF Data Binding

• WPF Interop with Windows Forms

• WPF/e

Page 4: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF Solutions

• Overview

• Styles and Resources

• 3D Rendering

Page 5: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF Vision

• Integrated, vector-based composition engine

– Utilizing the power of the PC throughout the graphics stack

• Unified approach to UI, Documents, and Media

– Integration as part of development and experience

• Declarative programming– Bringing designers directly into

application development

• Ease of deployment– Allowing administrators to deploy and

manage applications securely

Page 6: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .
Page 7: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF Controls

• Controls are ”lookless”– Behaviour and rendering is separated

• Based on basic shapes

• Includes Actions, Triggers, Styling

Page 8: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF Styles

• Styles sets up control rendering

• Microsoft delivers Expression Suite to create styles

• Styles can be shareable throughout the application

• Styles can be dynamic

Page 9: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF Data Binding

• Declarative

• Shared data sources

• Master / Detail Binding

Page 10: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF Databinding model

• Target– Any property, any element

• Source– CLR Object– WPF Element– ADO.NET– XML

• Dynamic– INotifyPropertyChanged, DependencyProperty or

PropertyDescriptor• Multiple models

– One Time– One Way– Two Way

• Value Converter

Control

“Data Item” Property

Binding

Property

Page 11: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Declarative DataBinding

<Image Source="truck.png"Canvas.Left= "{Binding Path=Value, ElementID=horzPos}"/>

<Slider Orientation= "Horizontal" Name="horzPos" Value="40"/>

{Binding Path=Value, ElementName=horzPos}

Page 12: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Static Data Sources

• Add to resource dictionary– Named source objects– Point to lists or methods

• Use with resource binding– {StaticResource theCars}

<Window> <Window.Resources> <ObjectDataProvider x:Key=“theCars" ObjectType=" {x:Type Cars}" /> </Window.Resources>

...

<TextBlock TextContent="{Binding Path=Bar, Source={StaticResource myData} }" />

Page 13: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Share Common Source

StackPanel

Image

HorizontalSlider

Value= {Binding Path=XPos, Source={StaticResource myData}}

Canvas.Left= {Binding Path=XPos, Source={StaticResource myData}}

DataContext= {Binding Source={StaticResource myData}}

Value= {Binding Path=XPos}

Canvas.Left= {Binding Path=XPos}

Page 14: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Using DataTemplates

DataTemplate

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

<DataTemplate x:Key="carTemplate"> <Border BorderBrush="Blue" BorderThickness="2" Background="LightGray" Margin="10" Padding="15,15,15,5"> <StackPanel> <Image HorizontalAlignment="Center" Source="{Binding Path=Image}" /> <Border HorizontalAlignment="Center" BorderBrush="Navy" Background="#DDF" BorderThickness="1" Margin="10" Padding="3"> <TextBlock FontSize="18" Text="{Binding Path=Model}" /> </Border> </StackPanel> </Border></DataTemplate>

Page 15: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Master Details Binding

• Use ItemsControl (e.g. ListBox) as master– Set

IsSynchronizedWithCurrentItem="True"

• Other bindings on same source will follow master

Page 16: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF Interop with Windows Forms

• How do I get from here to there?– Do I rewrite everything?– Too much code to rewrite– Existing plug-ins– Existing controls– Existing documents

Page 17: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF Interop with Windows Forms

• How do I get from here to there?– Do I rewrite everything?– Too much code to rewrite– Existing plug-ins– Existing controls– Existing documents

Page 18: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Using existing code with WPF

• Package into a control

• Use control inside WPF Content

• Look and feel issues

Page 19: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Mixed Applictaion Considerations

• Lower Initial Cost

• Potential higher TCO

• ”Airspace”

Page 20: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

”Airspace”

• One Pixel One Technology

WPF

File Edit View Help

Win32

DirectX

WPF

File Edit View Help

Win32

DirectX

Page 21: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

”Airspace”

• One Pixel One TechnologyFile Edit View Help

Win32

DirectX

WPF

File Edit View Help

Win32

WPF

DirectX

Page 22: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Interop best practices

Canvas

Chrome

Page 23: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Show me the Code

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;}

Page 24: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF/e

• Subset of XAML focused on interactive content

• WPF/E provides execution environments for the XAML subset– Browsers: IE, Firefox, Safaric, Netscape,

others... • Supported trough browser plug-ins

– OS: W2K, XP, Vista and MAC OsX– Devices: Windows Mobile, etc

Page 25: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF/E Architecture

Page 26: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Increased developer productivity

• Integrated Platform for UI, Text, and Media• Declarative Programming (XAML)• Brings Designers Into the Application• Development Process

– Tools for Designers: Microsoft Expression– Tools for Developers: Visual Studio– 3rd Party Support: Mobiform, Electric Rain

Page 27: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

WPF/E Programming model

• XAML and JavaScript in a web page– Access "WPF/E" via JavaScript– Support inline and external XAML/script

• XAML and .NET Framework code– "WPF/E" hosts a x-platform .NET runtime

• Code (C#) is compiled into an intermediate language (IL)• IL is run in a secure and “managed” environment

– "WPF/E" loads external package containing IL and XAML

Page 28: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

External package

<html>

<body>

<object/embed id=“wpfehost” size=“…”>

<param name=“source” value=“default.wpfe”/>

<param name=“startuppage” value=“default.xaml”/>

</…>

</body>

</html>

default.wpfe contains:- default.xaml (compressed)- It may also contain:

- Other XAML files- XAML and script files-Resources (images, media, fonts, others)

Page 29: .NET Framework 3.0 - Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer –Instructor @ Cornerstone –Blog @ .

Programming model

sample.xaml:

<Page Name=“p1”>

<Button Name=“b1”>Turn Red</Button>

</Page>

sample.cs (becomes sample.il):

b1.Click += new EventHandler(Button1_Click);

void Button1_Click(object sender, EventArgs e) {

p1.Background = Brushes.Red;

}