Two short points I'd like to make about working with WPF in Visual Studio 2008:
  1. In order to see Binding errors, you need to open the Output window while the app is running, since any binding error is silently dropped, but displayed there. There is also a Binding property called FallbackValue which you can set to "ERRRROOOORRR!!" :)
  2. XML files are seldom unformatted or having weird spaces and extra lines. Yet, there is not context menu for XML editors like the Format in ASP.Net as*x files. However, the option (and many more) is available in the Edit -> Advanced menu.
    • Format entire document: Ctrl+K, Ctrl+D
    • Format selection: Ctrl+K, Ctrl+F
  3. Unfortunately, some of the useful commands are just set up in the Options menu, like what to do with extra lines. So go to Tools -> Options -> Text Editor -> XAML -> Formatting.
    • To set it so that the XML is auto formatted at completion of start/end tag or when pasting code, go to the General option
    • To get rid of extra empty lines, go to the Spacing option and choose either Collapse multiple empty lines in content to a single line or Remove empty lines in content

It can't be done. Maybe in XAML 2009. In the old one, it just fails. I am using ReSharper and it automatically finds the controls in XAML in the loaded libraries and creates the appropriate namespace. For a library called "My Controls" it adds an "assembly=My Controls" at the end of the clr-namespace and the compilation fails with "Unknown build error".

The only solution I could find for this is to rename the library so that it doesn't have spaces in it. In my case the library was actually another project and I changed the name in the project properties to have underscore rather than space.

WPF Unleashed is a 2006 book in the Unleashed series about the new Microsoft paradigm on visual interaction, written by Adam Nathan. Windows Presentation Foundation is now the default Windows graphics framework, overriding Windows Forms, and it is based on XAML, which is used in Windows desktop applications, Silverlight applications, directly in Internet Explorer and even as a document template.

The book is nicely written, covering all the main characteristics of WPF, the functionality, the problems and tips on stuff that is not so clear. It also contains "Digging deeper" sections where some of the works "under the hood" are revealed. The book focuses more on the XAML implementation (the declarative part) rather that the code one, and I was happy to see that the code was written in C#.

All in all I liked the book and I wish I had more time to parse it completely. So far I've read the basic stuff (without the fancy graphics) so the first 10 chapters and I will wait for a moment of respite so I can detail some of the stuff I found in the book and how to implement them.

There are two things you need to do. First, set the project as having a neutral language. This is done in Visual Studio 2008 by going to the project's properties, selecting Application, clicking on Assembly information and setting the language. However, it doesn't set an UltimateResourceFallbackLocation. So you have to do it manually, by editing the Properties\AssemblyInfo.cs file and adding
[assembly: NeutralResourcesLanguageAttribute("en-US", UltimateResourceFallbackLocation.Satellite)]


The second thing is rather dumb. I haven't found ANY way to do it from Visual Studio. I just edited the csproj file manually. It needs
<UICulture>en-US</UICulture>
set in (under, actually) every <PropertyGroup> in it.

What that does is create a language folder in the bin directory when compiled with a localizable resource file. Using the locBaml utility in the Windows SDK you can turn a resources.dll in the language folder into a CSV, then back into a dll like this:
LocBaml /parse ProjectName.g.en-US.resources /out:en-US.csv
LocBaml /generate ProjectName.resources.dll /trans:fr-CA.csv /cul:fr-CA
.

You will not find locBaml in the Windows SDK folder except maybe as a sample project. The sample project can be downloaded here. Don't forget to compile it!

Some other useful links:
WPF Localization
Localizing WPF Applications using Locbaml
LocBaml + MsBuild + ClickOnce Deployment

Rick Strahl presents an easier and better alternative by using normal resx files! I don't want to copy (too much) from his post, so just read it:
Resx and BAML Resources in WPF

Tomorrow I start work on a WPF application that is supposed to be as modular as possible. Since I know almost nothing about WPF or modular applications, I started researching a little bit how it should be done. Basically I found only two ways I cared to expand my research on: Prism (patterns & practices Composite Application Guidance for WPF and Silverlight) and MEF (Managed Extensibility Framework).

Unfortunately I've only had time to do some Prism, although MEF seems to be the way to go. First of all it is a general framework, not limited to WPF/Silverlight and secondly it is used in the new Visual Studio 2010 release. What is amazing is that both frameworks come as freely available opensource.

Ok, back on Prism. The concepts are simple enough, although it takes a while to "get" the way to work with them. Basically you start with:
  • a Bootstrapper class - it initializes the Shell and the Catalog
  • a Shell - a visual frame where all the modules will be shown
  • a Module Catalog - a class that determines which modules will be loaded
  • an Inversion of Control Container - class that will determine, through Reflection usually, how to initialize the classes and what parameters they receive
  • a RegionManager - class that will connect views with Regions, empty placeholders where views are supposed to be shown
  • an EventAggregator - a class that is used to publish events or subscribe to events without referencing the objects that need to do that


Easy right? I don't even need to say more. But just in case you don't have a four digit IQ, better watch this four part video walkthrough:
Creating a modular application using Prism V2 - part 1
Creating a modular application using Prism V2 - part 2
Creating a modular application using Prism V2 - part 3
Creating a modular application using Prism V2 - part 4.

I did try to take the WPF Hands on Labs project and mold it with Prism and it partially worked. The problem I had was with the navigation controls. These work as a web application, where you call the XAML and it has to be a file somewhere, and you have events for the calling and returning from those "pages". I could find no way to encapsulate them so I could build no modules out of them and the whole thing collapsed.

So, for a quick walkthrough on using Prism with WPF.
Creating the core:
  1. create a new WPF application project
  2. reference the Prism libraries
  3. create the Bootstrapper class by inheriting UnityBottstrapper that will determine the Shell (a WPF window class) and set it as the application MainWindow, as well as create the type of ModuleCatalog (either take a default one or inherit one from IModuleCatalog) you want
  4. create the layout of the Shell and add region names to the controls you want to host the loaded modules (example <ContentControl Grid.Row="0" Margin="2" Regions:RegionManager.RegionName="SearchRegion"/>
.

Creating a module:
  1. create a new library project
  2. add a class that inherits IModule
  3. the constructor of the IModule can have different parameters, like an IRegionManager, an IUnityContainer, an IEventAggregator and any other types that have been registered in the container (I know it hasn't been initialized in the core, the catalog takes care of that). The IoC container will make sure the parameters are instantiated and passed to the module
  4. register views with regions and any additional types with the IoC container in the Initialize method of the module
  5. create view classes - WPF controls that have nothing except the graphical layout. Any value displayed, any command bound, any color and any style are bound to the default DataContext. The views will receive a view model class as a constructor parameter which they will set as their DataContext
  6. create the view model classes - they also can have any types in the contructor as long as they are registered with the IoC container, stuff like the eventAggregator or a data service or other class that provides the data in the view model.
  7. provide all the information needed in the view as public properties in the view model so that they can be bound
  8. subscribe or publish events with the event aggregator


As you can see, most of the work is done by the modules, as it should be. They are both communicating and displaying data using the event aggregator and the binding mechanisms of WPF. There are some differences between how WPF and Silverlight approach some issues. The Prism library brings some classes to complement the subset of functionality in Silverlight that are not needed in WPF. However, one can still use those for WPF applications, making a transition from WPF to Silverlight or a mixed project more easily maintained.

The video walkthrough (as well as my own text summary) are based on the rather new Model-View-ViewModel pattern, which many people call a flavour of MVC. It was created specifically for WPF/Silverlight in order to separate behaviour from user interface.

Expect more on this as soon as I unravel it myself.

Yay! My first real SilverLight post :)

Anyway, the problem is with controls in SilverLight that expect an URI as a parameter. It doesn't work. After trying all kind of stuff and googling a litle I found out that
  1. the path is relative to the web application ClientBin directory
  2. the path cannot contain .. or other directory/URI navigation markers like ~
  3. the SilverLight control does not have access to a Request object like a web page does


This link already discusses it: Silverlight 2.0 Beta 1 Uri inconsistency, but I also have an additional solution to the ones listed there.

Here are the solutions for this:
  • Provide an absolute Uri either statically or by generating it with this piece of code:
    New Uri(Application.Current.Host.Source.AbsolutePath + "../../../video.wmv", UriKind.Absolute)
  • Copy the images, videos, files into the ClientBin directory then only provide their name
  • Create virtual directories inside ClientBin that point to your resource directories. For example create a virtual directory Videos that points to the ~/Resources/Videos folder in the site, then simply use Videos/video.wmv as the URI


Of these three, the last I find the most elegant, even if the setup of the website itself might be rendered a lot more difficult by this.

It was great! Not only the setting was nice (the four star Smart hotel is exactly what I had expected a hotel should be, except the restaurant, maybe), but the weather was cool, the presentation helpful, the tutor (Aurelian Popa) was above expectations and the people pleasant. Not to mention a week away from boring stuff. ;) I feel it would be pointless to detail what we did there, since it was either my own personal life or the actual workshop (which involves work), so I will give you some impressions of the technology and point you towards the resources that would allow you to go through the same learning process.

The whole thing was about WPF and SilverLight and I can tell you two conclusions right now:
WPF/XAML/SilverLight are a great technology and I expect a lot of .Net applications to migrate towards it in the next 6 to 12 months.
The complexity of this technology is likely to put a lot of people off, therefore the tools like Expression Blend and the Visul Studio interface become completely indispensable and must evolve to have great ease of use and become more intuitive.

The entire presentation model allows one to use any graphical transformation available, including 3D, on any part of the interface. The controls are now without appearance. They come with a default appearance that can be totally replaced with your own. A weird example is to use a 3D cube with video running on each side as a button. Of course, the whole thing is still work in progress and some stuff is yet difficult to do. Besides, you know Microsoft: a lot of complicated things are easy to do, while some of the simplest are next to impossible.

You can taste the Microsoft confidence on this by watching them release an entire design oriented suite (Expression) and working on making Silverlight available on all platforms and browsers. Just the fact that Silverlight can access directly the browser DOM is enough to make me remove all those patchy javascript scripts and replace them with nice Silverlight C# code.

Enough of this. Go learn for yourself!

Tools:
Silverlight is at version 2 beta 2. That is painfully obvious when new bugs are introduced and beta 1 applications break. The Expression Blend tool is at version 2.5 June 2008 CTP and it has also a long walk ahead towards becoming useful. Visual Studio 2008 performs rather well when faced with XAML and WPF stuff, but the Resharper 4.0 addon helps it out a lot. You need the Visual Studio 2008 Silverlight Tools, too. After this compulsory tool kit you could also look at Snoop, Blender and Expression Deep Zoom Composer.

Learning material:
Simplest thing to do is to go to Silverlight Hands-on Labs or download the WPF Hand-on labs and download them all and run through the documentation script that is included with each one. There are video tutorials about how to use the tools, too. Here is one for Blend. Of course, all blogs and materials available online at the search of a Google are helpful, as well.

Community:
As any community, it depends on your desired locality and interests. You can look for local .Net / WPF groups or browse for blogs half way around the globe from you. From my limited googling during the workshop I can see that there are people talking about their issues with WPF and SL, but not nearly enough: the technology still needs to mature. I haven't really searched for it, but I've stumbled upon this site: WindowsClient.NET that seems to centralize WPF, Windows Forms and a bit of Silverlight information.