Tag Archives: WPF

Discover and compare existing MVVM frameworks !

A couple of weeks ago, I wrote a blog post where I compared the existing MVVM frameworks. This post became a bit famous in the WPF/Silverlight blog world and I received a lot of feedback to update the list, fix information, etc. I also got a request from Erik suggesting me to put all the datas in a matrix.

Today I’m proud to announce the MVVM frameworks Silverlight application (click the image to open the Silverlight3 page).

silverlight-mvvm-app

A couple of observation:

  • please contact me via this blog or twitter if you find incorrect information
  • I’m not judging anybody’s work by giving rating, it’s just my personal feeling to have an easiest way to sort the data

Hope you’ll like it 🙂

PDC09 : How VS2010 was built with WPF ?

PDC09

In my last blog post, I did a review of a PDC09 Session “Advanced performance tuning with WPF”. Today, I’m doing a review for another very interesting session “How VS2010 was built with WPF ?”. The video is available here.

vs2008tovs2010

Why did Microsoft choose WPF for VS2010 ?

  • Technological: prove the capabilities of WPF4
  • Architectural
    • Separated presentation
    • Support for long range road map (+10 years)
  • Key VS2010 features need it: Editor, Architecture Editor, Parallel tools debugging
  • Take an opportunity to give feedback for WPF4: when VS2010 development started, .Net 3.5 SP1 was just shipped and it was the right time to give feedback for the new features and fixes for WPF4.

It is worth noting that VS2010 is a project that is being watched carefully inside Microsoft. We can expect that more Microsoft applications will move to WPF in the next coming years.

What WPF features are used ?

  • Declarative UI using XAML
  • Databinding
  • Styles and templates
  • Application Resources
  • Interop Win32 (because they did not have the time to rewrite everything using WPF or because features doest not need to use WPF for example de WinForms designer…)
  • Integration with the message loop (to deal with particular focus issues)
  • New text stack (part of WPF4) based on DirectWrite

Staged approach

  • Define data models: a huge diagramming and architectural exercice
  • Replace the main window with WPF (only the window not its content !) to start the mix approach (managed/unmanaged, WPF/Hwnds)
  • Write new managed components: Window manager, command bar presentation
  • Scout with other VS teams
  • Test, Test, Test…

What were the challenges ?

  • Mixed mode application: native and managed code; WPF and HWNDs (Win32 or WinForms)
  • Keep existing extensions working and allow new extensions to take advantage of WPF
  • Don’t “stop the train” other teams were working at the same time on the product to add new functionalities
  • Text clarity
  • Performance
  • Focus management

You can watch the session here if you want more detail and demos of what I mention in this post.

How to measure rendering time in a WPF application ?

Last week, a colleague of mine asked me an interesting question: “I’m filling a control with content and I’d like to measure the time needed to render my control. How can I do that ?”

The first approach is to measure the elapsed time needed to instantiate and populate the control from C# code. We can use the StopWatch class to have a precise and easy to use measuring tool.

Stopwatch sw = new Stopwatch();
sw.Start();

for (int i = 0; i < 5000; i++)
{
  // here is the operation that fills the control
  this.canvas.Children.Add(new Rectangle());
}

sw.Stop();
MessageBox.Show("Took " + sw.ElapsedMilliseconds + " ms");

However this approach will not give good results because we're not taking into account the time needed to render elements in the visual tree. This is because elements are not rendered when you call the Add methods (for example in a Canvas) but when the visual tree is fully loaded.

A much better approach is to use the Dispatcher and request it to process an action at a priority right bellow the Render priority which is the Loaded priority:

dispatcherpriority

Using this trick, we ensure that all rendering actions have been completed. We can use the following code to do that:

Stopwatch sw = new Stopwatch();
sw.Start();

for (int i = 0; i < 5000; i++)
{
  // here is the operation that fills the control
  this.canvas.Children.Add(new Rectangle());
}

this.Dispatcher.BeginInvoke(
  DispatcherPriority.Loaded,
  new Action(() =>
  {
    sw.Stop();
    MessageBox.Show("Took " + sw.ElapsedMilliseconds + " ms");
  }));

Hope this helps !