290 likes | 304 Views
.NET Framework 3.0 - Presentation. 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. Agenda. WPF Solutions WPF Data Binding
E N D
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.
Agenda • WPF Solutions • WPF Data Binding • WPF Interop with Windows Forms • WPF/e
WPF Solutions • Overview • Styles and Resources • 3D Rendering
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
WPF Controls • Controls are ”lookless” • Behaviour and rendering is separated • Based on basic shapes • Includes Actions, Triggers, Styling
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
WPF Data Binding • Declarative • Shared data sources • Master / Detail Binding
WPF Databinding model Control • 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 Property Binding “Data Item” Property
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}
Static Data Sources • Add to resource dictionary • Named source objects • Point to lists or methods • Use with resource binding • {StaticResourcetheCars} <Window> <Window.Resources> <ObjectDataProvider x:Key=“theCars" ObjectType=" {x:Type Cars}" /> </Window.Resources> ... <TextBlock TextContent="{Binding Path=Bar, Source={StaticResource myData} }" />
Share Common Source DataContext= {Binding Source={StaticResource myData}} StackPanel HorizontalSlider Value= {Binding Path=XPos, Source={StaticResource myData}} Value= {Binding Path=XPos} Image Canvas.Left= {Binding Path=XPos, Source={StaticResource myData}} Canvas.Left= {Binding Path=XPos}
DataTemplate Using DataTemplates 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>
Master Details Binding Use ItemsControl (e.g. ListBox) as master Set IsSynchronizedWithCurrentItem="True" Other bindings on same source will follow master
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
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
Using existing code with WPF • Package into a control • Use control inside WPF Content • Look and feel issues
Mixed Applictaion Considerations • Lower Initial Cost • Potential higher TCO • ”Airspace”
”Airspace” File Edit View Help File Edit View Help • One Pixel One Technology Win32 WPF Win32 WPF DirectX DirectX
”Airspace” File Edit View Help File Edit View Help Win32 • One Pixel One Technology Win32 WPF WPF DirectX DirectX
Interop best practices Chrome Canvas
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; }
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
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
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
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)
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; }