Better XAML By Farr: WPF Line of Business Seminar
The WPF Line of Business seminar is a two day introductory provided by Microsoft outlining WPF, its benefits, architectural patterns practiced, and coding tips within line of business development. After developing in WPF for over a year I thought this would be a good seminar to attend to gage where I am at as far as WPF development. Well, I am very happy to find I follow very similar techniques and patterns as the Microsoft WPF experts Karl Shifflett and Jaime Rodriguez. The seminar took place on June 12th and 13th at the Sheraton in Arlington Heights, IL.
Well, I missed day one, which I don’t necessarily feel is bad for me. It went over very basic fundamentals of WPF and XAML. Below was the agenda I obviously missed.
Day One: - Lap Around WPF
- WPF Tools ( Blend, Visual Studio 2008)
- Graphics Subsystem
- Layout
- WPF Fundamentals and new concepts
- Application Model
- Dependency Properties
- Trees (logical & visual)
- Events
- Threading
- Resources
- Controls
- Styling
- Templating
- Q&A with instructors at end of day
So I wasn’t even supposed to go to Day Two however mother nature helped me out. I had a baseball game at a minor league stadium, didn’t really want to miss that even if it would give me the opportunity to meet Karl Shifflett. But rain washed that away and I went to Day Two. Of course, I was late. You can’t blame me. 9:00 on a Saturday morning in a suburb that is an hour away from the city and having five hours of sleep, well it was tough. Below is the agenda I actually took part in. Day Two: - WPF integration with Win32 and Windows Forms
- Data binding
- Introduction to Model-View-ViewModel
- Commanding in M-V-VM
- Views, Navigation and Transitions
- Data Validation
- Error handling, Model dialogs, Logging
- Unit Testing
- MVVM & LOB tips and tricks
- Q&A with the instructors
Karl Shifflett was the first presenter, and if you read my previous posts on XAML, I have been reading his blogs for a long time and can say they have helped changed my perception of development in WPF. I am going to summarize what he talked about as I am extremely tired after a long day of listening…. Karl talked about Databinding and how powerful it is. Databinding is basically WPF 101. He then talked about specific XAML features such as DataTemplates, ControlTemplates, ItemTemplates, ItemsPresenter, ValueConverters, and DataTempleteSelectors. I love ValueConverters but you do have to be careful not to overuse them. Basically, you need to decide whether to create a ValueConverter or convert parameters within the View Model itself. My rule is if a converter is needed in multiple Views then it warrants a ValueConverter, however if it is a date conversion for a specific view, it should be placed in the View Model. He briefly talked about data triggers, which Jaime would later say shouldn’t be used. Sorry Jaime I would disagree with that statement. I believe there is a separation between Business Logic and Design Logic and Data Triggers are completely valid for Design Logic.
Here are some things I learned from Karl:
DataTemplateSelectors - I don’t think they are necessary. You are basically creating a resource outside your View-ViewModel relation and I feel that this can be contained within this relation view DataTemplates, binding, and DataTriggers.
CollectionViewSource – Represents a layer on top of the binding source collection. It allows sorting, filtering, and grouping of data before being displayed in a view. Very, very cool….
Debug of Data Binding – Karl talked about an interesting way to debug data binding a little further. By adding System.Diagnostics and Trace levels to a binding source the output can display more detailed information if a binding error occurred. Below is an example of how this can be implemented.
1: <Window
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
5:
6: <TextBox.Text>
7: <Binding Source="{StaticResource myDataSource}" Path="PersonName"
8: diag:PresentationTraceSources.TraceLevel="High"/>
9: </TextBox.Text>
Jaime Rodriguez was the next presenter and started his presentation giving an architectural perspective of the MVVM pattern. I was happy he gave props to Martin Fowler, one of the founding architects of this pattern. Jaime explained the concept of MVVM and the idea behind the separation between Views and Models. He also talked about the benefits of MVVM such as modularity, loosely coupled code, and testability.
Jaime next talked extensively about Commands. He discussed RelayCommands, DelegateCommands, and the DelegateCommand in the MVVM Tool kit. Commands are very important to binding in that they enable you to route events from Views to ViewModels. The benefit of this is that you do not have to write any code behind in the view and your business logic from a command is separate from your design. I have used RelayCommands and DelegateCommands in the past. Relay Commands use CommandManager which provides command related utility methods that register command bindings. DelegateCommands are part of PRISM, so to use DelegateCommands you need to add the Microsoft.Practices.Composite.dll. DelegateCommands in the MVVM Tool kit are quite interesting as you do not need a Command Manager nor the Microsoft.Practices.Composite.dll. I definitely have to play with this a little more.
Karl finished with some talk about Validation in WPF. Karl gave examples of when to use validation in XAML and when to apply validation to business layer development. He also talked about his Ocean Framework and validation using an AdornerElementPlaceHolder. AdornerElementPlaceHolders are used for custom validation templates to provide visual feedback when a user input is not valid. Basically, the add validation capabilities within XAML.
Well, I know this post is a little overdue as the seminar was a week and a half ago. But I finally am able to get it out there. If you need more information about Jaime and Karl you can view their respective blogs, Jaime, and Karl. They both have information about the WPF LOB seminar in Chicago which includes demos and slides.