Google Search

Google
 

Wednesday, April 14, 2010

Windows Presentation Foundation 4 Plumbing and Internals


Windows Presentation Foundation 4 Plumbing and Internals

Come get the inside scoop on how Windows Presentation Foundation (WPF) powers all its rich services – like layout, databinding, and animation. There is a lot of heavy lifting done for you under the hood; in this session, we crack open these system components, including the trees (visual, logical, and inheritance), the property system and its change notification, and a few of the routing systems that all messages go through. Bring your hard-hat for this one!


Initialization


Demystifying the processes of initialization and binding.

Inheritance


Logical and visual inheritance in WPF 4.

Responsiveness


How to improve application responsiveness in WPF 4.

Background Worker


Moving tasks into the background.

Conclusion


Other resources and a brief Q&A session

00:00:00



Welcome to session WPF4 Plumbing and Internals, we'll be diving into it shortly, but, this is the last day of PDC. Have you gotten a lot out of it so far? Fantastic!


00:00:11



Wide awake? I know it is a tough time slot at least I didn't have the first thing in the morning on the final day. That can be really rough.


00:00:18



My name is Blake Stone, I'm an architect here at Microsoft, working on a wide variety of .NET things. Really happy to be able to talk to you about the wpf side of things today. But when we thought about plumbing and internals, there are a couple of ways to go about a subject like this.


00:00:35



One of them is to really dive in and tell you all of the inside scoop. How all the comments are writtin in iambic pentameter. How every single variable has to rhyme with some other variable in the same file. But those are the kinds of things that are interesting to us, so the poetry of wpf will have to remain hidden for now. Instead, we're gonna focus on what's of interest from your perspective.


00:08:51



So this whole question of "when my properties are set" is a pervasive theme. If we think about it, in some ways it's kind of a trick question. If I ask "when is this prperty going to get set?", well a lot of properties never get set at all and so the classic phrase here, thank you very much to members of the WPF team for suggesting, these properties are sought. If I have an inherited property, if I have a property in a style, these things never get set at all.


00:09:17



And so look at the collection of methods that are available to me. SetValue() only gets called if I have a local value set, if I have a local binding, if I have an explicit local value. GetValue() is not really a parallel to that, it doesn't get the local value, what it gets is the effective value, where the effective value is the result of walking a chain of possibilities.


00:09:38



It might be that my property is animated, in which case I get the current animated value. It might be that I have a local value set, if no animation is going on, that's what I'll get. If that's not present, we'll look at triggers in styles. They take precidence over other setters in styles. If they're not present, we'll look at the style. From there, if it's not present, we'll actually walk up and look potentially for inherited values for inherited properties.


00:10:00



So it's possible that it comes from a wide range of places, and you should not count on SetValue() being called, because that's only the case for your local value being set.


00:10:11



In the case of styles and animations, literally never happens at all.


00:10:14



New feature in WPF 4, though, there are times when it would be really handy to temporarily change the value of a property without actually replacing its local value.


00:10:25



Let's have a look at a specific case in this application where that would be incredibly handy.


00:18:17



Thinking about inheritance, though, we talked about inheriting data contexts, and inheritance is one of those other topics where people get caught up a lot. Specifically, it's a question of what the logical tree is, what the visual tree is, and then what some people refer to as the inheritance tree. There really isn't an inheritance tree as we'll see just in a sec. The issue is that what inheritance comes from isn't strictly the logical tree, it isn't strictly the visual tree, it's kind of a hybrid of the two and in some cases it isn't related to either. So we'll walk through and think about that.


00:18:52



Look at the example code that we have here, and what we have is a grid that contains a button that's templated. The button contains a text block. And so, the logical tree is the containment order. The grid contains a button, the button contains a text block. The template is set on a property of the button, it's not actually contained in the button, so it's not part of the logical tree. So the blue here really represents the logical tree.


00:19:21



However, it's not that the template isn't involved at all in figuring out what's presented. In fact, it's very much involved. When we actually go ahead and run this code, during layout this template is going to get expanded. Our visual tree will actually have a few other elements in it, here. We get a content presenter inside a stack panel so that the text block can actually be properly presented on the button.


00:19:45



What's interesting in this case is that we have now potential confusion about where my data context comes from. The stack panel has a data context that got inserted for me between the text block and the button. The grid also has a data context, so where does it come from? The answer is, the inheritance is designed to not suprise you.


00:20:06



If somebody were to come along and create a new template, and inject a bunch of visuals and change the data context under you, it would surprise the author of the original XAML. This is a rare case where the template's actually embedded inline. Usually, you get it from somewhere else. It may be part of the system resource, what have you.


00:20:23



So, what we do instead is when you're actually trying to inherit properties, first we will look for the logical parent, and we will track the logical parent in preference to anything else when looking for an inherited property.


00:33:46



The ideal approach would be for me to actually learn about threading. And doing all the threading work yourself is kind of a pain. There's a lot of setup that you need to think about, there's a lot of communication back and forth between the threads, but BackgroundWorker does an awful lot of the work for you. And so for trivial cases, BackgroundWorker's a great way to go.


00:34:11



What you wind up with is the UI thread where all of the sort of mainline WPF things go on. WPF has it's own render thread that you really don't need to worry about that tries to offload some of the raw rendering tasks to another thread for some parallelism. But BackgroundWorker creates a whole new set of threads so that if I'm doing a bunch of operations it will manage a pool of threads for me. It worries about how many threads are optimal for my hardware. I don't need to think about that at all. And what runs on those worker threads is my code. I get to define everything that runs there. WPF isn't involved, so I have free reign.


00:34:52



It's great for these kind of long-running or blocking operations. But, you should think about this. DispatcherObjects and anyhthing else that's connected to WPF are sort of off-limits from your BackgroundWorker code. And what's a DispatcherObject? Well in WPF, everything is a DispatcherObject, right? You get into visuals, you get into FrameworkElements, you get into Brushes, you get into Freezables. Everything is a DispatcherObject, which means it's got tight affinity to a single thread, the UI thread in this case, and you can't use it anywhere else.


00:48:54



Virtualization is a wonderful, wonderful technique. I highly recommend it. In practice there are a bunch of ways of dealing with this. The root question is "why am I bothering to create all of these visuals that aren't actually going to be displayed? why am I loading all of the images to create all of these thumbnails when they're not actually going to be used?"


00:49:14



Virtualiziation is basically a slight-of-hand mechanism, and if you've got a long scrolling list or you've got an enormous table that you want to scroll around, virtualization says I'm only going to create the things that I actually need to create the display that's on the screen at the time.


00:49:29



Luckily, a lot of things do this automatically. ListBox virtualizes by default, so does DataGrid, which you may have been using from the toolbox in 3.5, but honestly is a WPF4 new feature.


00:49:43



The way I deal with this is in my control, I need to make sure that anything that creates a bunch of items uses an appropriate panel. And so there's an ItemsPanelTemplate that allows me to define what panel is going to be used. I've just got a list in mine, so what could possibly have gone wrong?




[+/-] Show Full Post...

Multi-Touch on Microsoft Surface and Windows 7 for .NET Developers



Multi-Touch on Microsoft Surface and Windows 7 for .NET Developers

Multi-touch is going mainstream as part of Microsoft Surface and Windows 7. Come to this session to learn about how to create innovative new user experiences with touch – and how .NET developers can share code between both of these platforms. You’ll get a deep dive on the new touch capabilities in WPF 4 and the subset in Silverlight 3. You will also see how the unique capabilities of Microsoft Surface take multi-touch to a whole new level.


Multi-Touch Overview


An overview of multi-touch technology.

Surface


How Microsoft Surface and WPF interact.

WPF 4


Touch capabilities in WPF 4.

Silverlight


Multi-Touch on the web using Silverlight.

Multi-Touch Manipulations


Multi-Touch manipulations and manipulation containers.

Inertia


Inertia behaviors, manipulation events, and an intertia demo.

Touch Panning


Touch panning demo and support.

WPF Extensions


Surface's extensions of WPF

Toolkit and SDK


Surface toolkit for Windows Touch and surface SDK features for multi-touch.

Surface


More about the capabilities of Surface, beyond just multi-touch.

Roadmap


Development roadmap for Windows Touch.

Wrap-up


Resources, conclusion, and Q&A


[+/-] Show Full Post...

New Developer Tools in Windows Embedded Standard 2011


New Developer Tools in Windows Embedded Standard 2011

See how Windows Embedded Standard 2011 fuses the power and functionality of Windows 7 with the flexibility and workflow needed for the embedded developer to make devices come to life. Discover 2 distinct development experiences, Image Based Wizard v. Image Configuration Editor, and explore the workflow for creating an embedded device with Windows Embedded Standard 2011.


Windows Embedded Family


An introduction to the family of Windows Embedded products.

Toolkit


Standard 2011 embedded developer toolkit.

Building Blocks


Image building blocks.

Image Building


The image building process and a demo of the image builder wizard.

Configuration


Image configuration and a demo of the image configuration editor.

Q&A


A brief Q&A session, and the wrap-up of the discussion



[+/-] Show Full Post...

Custom Behaviors for Advanced Microsoft Silverlight UI Effects



Custom Behaviors for Advanced Microsoft Silverlight UI Effects

Learn how to light up your Silverlight application by using behaviors to add physics-based animation and rich interactivity. Hear tips and tricks on how to create advanced behaviors, techniques to make them extensible, and how they can be integrated to create immersive applications and enhance interactive games.


Goals


Goals and reasons for using custom behaviors.

Triggers, Actions, and Behaviors


Triggers, actions, and behaviors. Demonstrations.

Easing


Using easing functions.

Integration


View-ViewModel integration.

Visual State Manager


How to use the Visual State Manager.

Demonstrations


Ripple click, explode click, and other features.

Wrap-up


Links to other resources, conclusions, and a brief Q&A session.


[+/-] Show Full Post...

Video sitemap



Custom Behaviors for Advanced Microsoft Silverlight UI Effects
Learn how to light up your Silverlight application by using behaviors to add physics-based animation and rich interactivity. Hear tips and tricks on how to create advanced behaviors, techniques to make them extensible, and how they can be integrated to create immersive applications and enhance interactive games.

New Developer Tools in Windows Embedded Standard 2011
See how Windows Embedded Standard 2011 fuses the power and functionality of Windows 7 with the flexibility and workflow needed for the embedded developer to make devices come to life. Discover 2 distinct development experiences, Image Based Wizard v. Image Configuration Editor, and explore the workflow for creating an embedded device with Windows Embedded Standard 2011.

Multi-Touch on Microsoft Surface and Windows 7 for .NET Developers
Multi-touch is going mainstream as part of Microsoft Surface and Windows 7. Come to this session to learn about how to create innovative new user experiences with touch – and how .NET developers can share code between both of these platforms. You’ll get a deep dive on the new touch capabilities in WPF 4 and the subset in Silverlight 3. You will also see how the unique capabilities of Microsoft Surface take multi-touch to a whole new level.

Advanced Graphics Functionality Using DirectX
The number of PC configurations is exploding. With the onset of netbooks as well as high-end desktop systems using the latest in graphics hardware, creating an application that can target all of these systems is getting harder every year. Join us as we explore the many options available in Windows 7 to facilitate graphics development across all different hardware configurations, from low-end integrated to top of the line discrete GPUs. Learn advanced performance and rendering techniques for Direct2D and DirectWrite, and the interoperability of Windows 7 technologies for making slick, high-quality graphics for your applications of the future.

Windows Touch Deep Dive
Windows provides applications a default experience for gestures and touch interaction. Applications that want to go beyond that basic experience have a powerful platform to build on top of. This session is targeted at developers interested in building touch-optimized experiences. We look closely at some of the more powerful portions of the Touch platform, like manipulation and inertia processors, as well as cover real-world problems that developers have encountered and overcome. Come help build the next generation of user experiences!

Developing with the Windows API Code Pack for .NET Framework
The Windows API Code Pack for Microsoft .NET Framework provides a source code library that can be used to access some new Windows 7 features (and some existing features of older versions of Windows operating system) from managed code. These Windows features are not available to developers today in the .NET Framework. This session will show you how to access features like taskbar integration, jumplists, libraries, sensor platform, Direct2D, and more.

Advanced Windows Presentation Foundation Application Performance Tuning and Analysis
Come walk through the top performance and coding pitfalls in large-scale, complex Windows Presentation Foundation (WPF) applications. Learn to use the performance analysis tools and methodologies to find problems in real application scenarios, and discuss solutions to optimize your WPF application for maximum performance. Understand how to tackle a non-performing app and transform it into a quality application that runs as well as it looks.

Windows Presentation Foundation 4 Plumbing and Internals
Come get the inside scoop on how Windows Presentation Foundation (WPF) powers all its rich services – like layout, databinding, and animation. There is a lot of heavy lifting done for you under the hood; in this session, we crack open these system components, including the trees (visual, logical, and inheritance), the property system and its change notification, and a few of the routing systems that all messages go through. Bring your hard-hat for this one!

How Microsoft Visual Studio 2010 Was Built with WPF 4
Get an insider’s look at how Microsoft created the next-generation, large-scale integrated development environment experience using Windows Presentation Foundation (WPF) 4. Learn best practices and hear real-world experiences in developing mixed Win32-WPF applications that combine WPF content with Win32 HWNDs. Discover how Visual Studio 2010 uses the new WPF text-rendering stack that utilizes DWrite.

Embodiment: The Third Great Wave of Computing Applications
Come hear about the next major wave of computing applications from Butler Lampson, a recognized leader in modern networking, and alumnus of Berkeley, Xerox PARC, and Digital’s Systems Research Center. Learn how computing applications evolved beginning with simulation, then communication, and how we're beginning to use computers for embodiment: nontrivial interactions with the physical world. Today there are sensor networks like the Inrix traffic information system, robots like the Roomba vacuum cleaner, and cameras that can pick out faces and even smiles. In a few years we will have cars that drive themselves, glasses that overlay the person you are looking at with their name and contact information, telepresence systems that make most business travel unnecessary, and other applications as yet unimagined. Hear about the new embodiment wave of computing applications from one of the leaders in the field.




[+/-] Show Full Post...