Changing the layout of a WPF TreeView to look like multiple ListBox

WPF No Comments »

Last week at work I was requested to create a new control which should have the behavior of the WPF treeview with a template involving multiple ListBox. To understand what I mean, I wanted to change the layout of this:

To this:

Of course, selection must work properly:

I asked a question on StackOverflow about this control because I didn’t find any easy way to do it. I though at the beginning that playing with the templates of the TreeView and TreeViewItem would do the trick but it didn’t.

The solution I finally choose involves creating multiple ListBox and wire them together using DataBinding:

  • I create a new CustomControl which inherits Control (I couldn’t use neither Selector or TreeView because I wouldn’t have been able to manage the SelectedItem property from the derived class)
  • In the template of this CustomControl is an ItemsControl. This ItemsControl has its ItemTemplate property set to a DataTemplate containing a ListBox.
  • The CustomControl has a Depth property of type int. This property indicates the number of ListBox that should be generated.
  • The CustomControl automatically databound ListBoxes together: each ListBox’s ItemsSource property is databound to the SelectedItem’s children property of the previous ListBox in the visual tree.
  • The CustomControl has a SelectedItem property and a SelectionChanged event (like Selector-derived class).
  • I added an IsReallySelected attached property to the ListBoxItem which are generated. This enables to databing an IsSelected property of the ViewModel class behind the control with the IsSelected of the ListBoxItem. I had to create an attached property because its value is true when the ListBoxItem is selected AND the parent ListBox has IsSelectionActive set to true.

Here is the result:

You can download the source code of this sample (VS2010 RC solution).

Mix10 is coming : Windows Phone 7 series sessions announced !

Events, Silverlight, Windows Phone No Comments »

Next monday, Mix10 will start in Las Vegas. Even though it’s a little bit far from my place here in France I’ll try to give feedback after the keynotes and as soon as first videos will be available. I’m sure you’re aware that major announcements this years at Mix will be about the Windows Phone 7 series.

To make the long story short :

I’m sure you realize that we are going to a very capable and powerful mobile platform here:

  • all existing .Net and Silverlight developers are going to be able to write apps for the Windows Phone (this is HUGE)
  • we are going to finally have the 3 screens version of Microsoft: develop once and then run on your mobile, your PC and your TV (XBox)

Mix10 website now contains the name and the description of the sessions which are dedicated to the Windows Phone 7 series:

If you’re using Twitter, make sure to watch the #wp7 hashtag. It make not any doubt the next week is going to be very informative about Windows Phone 7 series.So stay tuned !

Using Reflector to debug a .Net app in Visual Studio without the original source code

Tools, Visual Stutio No Comments »

Many .Net developers use to say “if you’re a serious developer, then you MUST Reflector”.

I would like to add another statement: “if you want to have an insight and powerful look at how things works internally, use Reflector Professional”.

Last Wednesday, RedGate released a new version of Reflector. You’re probably going to download it soon or later because your actual version is going to expire. When you’ll download the free version, you’ll automatically get a trial (14 days) of the professional edition. Nice, but what’s so special about this edition ?

Let’s see a demonstration of what can be done using Reflector Pro. The following is not an ad for RedGate, I’m just totally amazed by their new feature :-)

1. Reflector is now integrated into Visual Studio (2005, 2008 and 2010 RC):

2. Select the “Choose Assemblie to Debug…” option to select .Net assemblies for which you don’t have the source code. In this example, I’m using one of the Blend3’s assemblies:

3. Once the process is completed, select the “Explore Decompiled Assemblies” option:

4. Browse to your target assembly and select an interesting type:

5. Put a breakpoint in the code, like you do every day when you debug an app:

6. Run the executable

7. Debug Blend3’s source code ! Use breakpoints, step into methods, inspect variables…

And that’s it. With Reflector Professional, you can:

  • Decompile third-party assemblies from within Visual Studio
  • Step through decompiled assemblies and use all the debugging techniques you would use on your own code. This is incredibly powerful as we saw by debugging Blend3″s source code !

Reflector Professional is available for about 195$ on RedGate website

Minor update to the Silverlight MVVM frameworks explorer

Silverlight, WPF 1 Comment »

Thanks to the readers who gave me feedback on my Silverlight MVVM frameworks explorer I updated the application this morning in order to fix some problems.

Here is the change set:

  • fix incorrect URLs
  • fix incorrect “Silverlight Support” options. As Laurent Bugnion said in the comments, his MVVM Light framework was the only one supporting Silverlight which was strange…
  • links now open in a new window

Click on the following image to launch the Silverlight application.

About adding new frameworks, I’m not sure to add those which targets a much larger domain than MVVM itself. CompositeApplication guidance for example is a lot more than MVVM…

WPF internals part 2 : how the WPF controls are organized ?

.Net, Silverlight, WPF No Comments »

A couple of weeks ago, I started a series of articles about WPF internals organization. In the first article I did a tour of the core WPF classes. In this second part, I’m reviewing the organization of the various controls that exist in the framework.

Because the image of the diagram is pretty big, I decided to use Silverlight DeepZoom and the result is just below this text :-) You can download the full image resolution here. Please use the full screen button in the upper right corner of the viewer for the best browsing experience.

    Here are general remarks that might help you get information from those diagrams.

    The top level Control class:

    • Defines general UI properties such as Background, Foreground, BorderBrush and BorderThickness
    • Defines a set of properties to control font rendering: FontFamily, FontSize, FontStyle…
    • Has a DoubleClick event (other mouse events such as MouseUp/MouseDown comes from the UIElement class)

    Below the Control class, we have (this list is not complete):

    Below the ContentControl class we can find many existing WPF controls:

    General other remarks:

    • It’s funny to see that both Window and UserControl inherits from ContentControl. Before doing the diagram I though that Window came from somewhere else :-)
    • Having those diagrams in mind (or on a screen !) is very useful when you need to create your own custom control
    • We can see the differences between creating a custom control (inherit from Control or derived class) and a UserControl (inherit from UserControl)
    • .Net4 will introduce new controls (not in this diagram) in the WPF framework such: DataGrid, Calendar, TimePicker

    kick it on DotNetKicks.com

    Review of 2009 blog posts

    General No Comments »

    In the past year, I’ve posted more than 30 articles on my blog. Here is a summary of those posts (link in bold are those which got the most traffic during the year). Obviously, MVVM was a very hot topic during 2009 :-)

    January

    February

    March

    April

    May

    July

    August

    September

    October

    November

    Windows Azure challenge

    Events No Comments »

    A couple of weeks ago, the French developpez.com website launch a challenge in collaboration with Microsoft to help developers discover the Windows Azure platform.The goal was to succeed 5 different steps in order to win the challenge and get two prizes. The first one was a wifi teeshirt and the second one the new Microsoft Arc Mouse.

    It was my first real experience with the Azure platform and I was very happy to be able to manipulate the platform through various real-world example. The steps were the following:

    1. Deploy an existing application on Azure
    2. Modify an existing application and then deploy it on Azure
    3. Deploy an existing application using Blob storage
    4. Fix a Winforms application using the Azure API to backup files and folder
    5. Answers several questions about the Azure platform

    The steps were both educational (each time we discovered a new feature) and challenging (we must make it work !). I would like to thank very much the organizers of this event: Jérôme Lamber, Louis-Guillaume Morand, Phillippe Vialatte, Pierre Couzy and Thomas Lucchini.

    Hopefully, we’ll see more challenges in the future on the developpez.com website.

    2010 roadmap

    General No Comments »

    I wish a happy new year to all my readers across the web. I thank you for all the feedback I got during the past year and I hope we will be able to exchange more in 2010. In this post, I’m sharing with you my roadmap for interesting events and dates in 2010:

    • January 7-10th: CES (Consumers Electronic Show) in Las Vegas
    • February 8th – 10th: Microsoft TechDays in Paris. I’ll be there  for the event and I’m hoping to be recruited by Microsoft for the ATE (Ask The Expert) stand where I’d like to share my WPF experience with other developers
    • March: release of Visual Studio 2010 and .Net 4.0 RC
    • March 15-17th: MIX10 in Las Vegas. We can expect more announcements about Silverlight4 and hopefully some information about the future of Silverlight on mobile and demos of Windows Mobile 7 as well
    • April: release of Visual Studio 2010 and .Net 4.0 final
    • Autumn : release of Windows Mobile 7

    I think 2010 is going to be an exciting year with VS2010, .Net4, Silverlight4 and hopefully a mobile version of Silverlight too. Stay tuned :-)

    Discover and compare existing MVVM frameworks !

    .Net, Silverlight, WPF 12 Comments »

    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 ?

    .Net, Events, Tools, Visual Stutio, WPF No Comments »

    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.

    WP Theme & Icons by N.Design Studio
    Entries RSS Comments RSS Log in