Rest in Peace, TuO

By Jerome at February 26, 2007 02:38
Filed Under: Misc

Jean-Michel Hervé, aka TuO, has left us yesterday. I've worked with him a few times during my demomaking years when I was an active member of Orion, and I had a lot of respect for the guy.

He was a particularly gifted coder, and will be remembered for many things like the excellent VIP2 invitation demo released in June 2000 when he was a member of the PoPsY TeAm. Lately, he was working in lyon as a developer at Eden Games.

Rest in peace, my friend.

Atlantic Shores of France

By Jerome at February 19, 2007 13:31
Filed Under: My Life

If you've never been to france, there are some beautiful places facing the atlantic ocean that are worth visiting, for their calm and their beautiful shores.

Cabourg is one of them, and you can see here some shots I've taken there :)

WPF DataBinding and Application Settings

By Jerome at February 15, 2007 21:47
Filed Under: .NET

Well, yet an other post on WPF and some DataBinding. But this time, this is about DataBinding to application settings that are automatically generated by visual studio. These settings come in handy when you want to save your application settings per user, or have some application wide settings. In my case, I wanted to have my application to remember its size and position, as well as the window state.

WinForms were providing an UI to do this, and I wanted to have all that functionality back. It is not all that "visual" as WinForms can do it, but it works rather well. I guess that Orcas will provide a way to do this visually.

All I had to do to use these settings from XAML was to create a resource to be usable for DataBinding, from a separate file :


File: SettingsRes.xaml



<ResourceDictionary xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation

                    xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml 

                    xmlns:settings = "clr-namespace:WindowsApplication2.Properties">

  <ResourceDictionary.MergedDictionaries>

    <ResourceDictionary>

      <settings:Settings x:Key="settings" />

    </ResourceDictionary>

  </ResourceDictionary.MergedDictionaries>

</ResourceDictionary>

WindowsApplication2 is the default namespace for the application, and since the Settings class is automatically generated, the default namespace is used. This resource will be used application wide and is referenced like this :


<Application.Resources>

  <ResourceDictionary>

    <ResourceDictionary.MergedDictionaries>

      <ResourceDictionary Source = "SettingsRes.xaml"/>

    </ResourceDictionary.MergedDictionaries>

  </ResourceDictionary>

</Application.Resources>

This is handy because resources are separated in multiple files. I also add here references to value converters, when I have to use them everywhere in the application. Value converters, yet an other interesting subject. Maybe in an other post :)

Now, about binding the data. We want to bind the Width, Height and WindowState of the default Window to some settings in the ApplicationSettings.

Here's what to do :


<Window x:Class="WindowsApplication2.Window1"

        xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation

        xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml

        Height = "{Binding Source={StaticResource settings}, Path=Default.MainWidth, Mode=TwoWay}"

        Width = "{Binding Source={StaticResource settings}, Path=Default.MainHeight, Mode=TwoWay}"

        WindowState = "{Binding Source={StaticResource settings}, Path=Default.MainState, Mode=TwoWay}">

We create three bindings, each for an attribute, and set the source to the "settings" resource. The interesting part here is that the even thought the property we use is static, Settings.Default here, the Binding engine does seem to support it.

Setting the binding path to Default.MainWidth binds to the appropriate property. The last parameter instructs the binding to set the value of the property when the binding destination value changes, which can be the actual window height, for instance. The type of the property does not need to match the destination exact type, and since the type of the WindowState property is not known by VS2005 settings designer by default, setting the type to string seems to be enough.

Simple and easy. Now my application remembers where it was !

The sample here is a bit more complex, since it includes code to actually save the settings. But this is nothing really complex.

Man ! I like WPF... !

WPF DataContext and CurrentItem

By Jerome at February 13, 2007 15:23
Filed Under: .NET

DataBinding is one of the technologies I like the most. 

Winforms did a fine job introducing the concept, but it was pretty easy to be stuck when trying to perform complex databinding. .NET 2.0 brought the concept of BindingSource, which eased the management of multiple "Current items" on a single form. You might have encountered this when creating multiple master/detail views on the same form. That was the case when you wanted to walk through a set of tables through their relations, say down to three levels.

WPF has a far more advanced DataBinding engine and introduces the concept of DataContext. There's the notion of a hierarchy of DataContexts and a databound control uses the nearest DataContext available.

An example is better than a thousand words. Here's a data source :


<xmldataprovider x:key="ops" xpath="/data/level1">

  <x:XData>

    <data xmlns="">

      <level1 name="1">

        <level2 name="1-1">

          <level3 name="test">Some Value</level3>

          <level3>Yet an other value from level 3</level3>

        </level2>

        <level2 name="1-2">

          <level3>Some other Value</level3>

          <level3>Yet an other Value</level3>

        </level2>

      </level1>

      <level1 name="2">

        <level2 name="2-1">

          <level3>Some Value</level3>

          <level3>Yet an other value from level 3</level3>

        </level2>

        <level2 name="2-2">

          <level3>Some other Value</level3>

          <level3>Yet an other Value</level3>

        </level2>

      </level1>

    </data>

  </x:XData>

</xmldataprovider>


It's a three level hierarchy, and I want to display this data, by recursively selecting each level in a ListBox to see its content.

Now, let's bind this data to a list box, contained in a GroupBox to be a bit more readable :


<GroupBox Header="Level 1" DataContext="{Binding Source={StaticResource ops}}">

  <ListBox ItemsSource="{Binding}"

           DisplayMemberPath="@name"

           IsSynchronizedWithCurrentItem="True" />

</GroupBox>

This performs a binding to the attribute "name" of the level1 node list. The IsSynchronizedWithCurrentItem tells the listbox to set the CurrentItem of the current DataContext, which can be used to fill the next ListBox for the level.

Now, to add a new DataContext level, let's add a new GroupBox, and a stack panel to have a nice layout :


<GroupBox Header="Level 1"

          DataContext="{Binding Source={StaticResource ops}}">

  <StackPanel Orientation="Horizontal">

    <ListBox ItemsSource="{Binding}"

             DisplayMemberPath="@name"

             IsSynchronizedWithCurrentItem="True" />

    <GroupBox Header="Level2"

              DataContext="{Binding Path=CurrentItem}">

      <ListBox ItemsSource="{Binding}"

               DisplayMemberPath="@name"

               IsSynchronizedWithCurrentItem="True" />

    </GroupBox>

  </StackPanel>

</GroupBox>

Now, there is a new DataContext for any children of the second group box, and is having the CurrentItem of the upper DataContext as a root. This is fairly easy to do, so let's do this for the final level.


<GroupBox Header="Level 1"

          DataContext="{Binding Source={StaticResource ops}}">

  <StackPanel Orientation="Horizontal">

    <ListBox ItemsSource="{Binding}"

             DisplayMemberPath="@name"

             IsSynchronizedWithCurrentItem="True" />

    <GroupBox Header="Level2"

              DataContext="{Binding Path=CurrentItem}">

      <StackPanel Orientation="Horizontal">

        <ListBox ItemsSource="{Binding}"

                 DisplayMemberPath="@name"

                 IsSynchronizedWithCurrentItem="True" />

        <GroupBox Header="Level3"

                  DataContext="{Binding Path=CurrentItem}">

          <StackPanel Orientation="Horizontal">

            <ListBox ItemsSource="{Binding}"

                     IsSynchronizedWithCurrentItem="True" />

            <Label Content="{Binding Path=CurrentItem}" />

          </StackPanel>

        </GroupBox>

      </StackPanel>

    </GroupBox>

  </StackPanel>

</GroupBox>

Each time a new DataContext is set, a new CurrentItem is created. That kind of behavior was hard to reproduce using DataBinding with WinForms; WPF allows it only by using a simple declarative syntax. Easy and powerful.

Also there is a fine feature that came up when using this DataContext and CurrentItem : The CurrentItem "chain" for a specific path is -- when the data source does not change -- kept if you change the selection, and come back to that particular path. Pretty interesting.

Here is a working xaml sample of this post.

Did I say that a really like WPF already ? :)

Small blog update, with Url Rewriting

By Jerome at February 11, 2007 16:33
Filed Under: .NET

Since this little website upgrade to add the blog, posts have been indexed by google with an ugly internal uniqueidentifier of mine.

Incidentally, that does not index well in google. Since the url to a post does not explain what the destination is about, I decided to add an url rewriting HttpHandler, to have the url containing the title of each post or category.

The part about writing the url rewriter has been covered over and over, oh and over, so I won't talk about it here.

Actually, I'm using CrystalTech web hosting -- like my brother Matthieu -- which works really fine, and does a fine job providing ASP.NET 2.0 services.

Their service is providing a tweaked Medium trust level to users, so hosted application have be configured that way. By tweaked, I mean that they re-enabled Reflection, Web, ODBC and OLEDB permissions from the Medium trust profile.

Anyway, you have to deal with Partially Trusted Callers. My application uses a class library in a separate assemnly, which needs to have the AllowPartiallyTrustedCallers attribute set, because of the Medium trust. That avoids this :

[SecurityException: That assembly does not allow partially trusted callers.]

So, if you choose CrystalTech web hosting, remember to try your website under the Medium trust profile to avoid suprises, with this :

<system.web>
   <trust level="Medium"/>
</system.web>

Also, on the side of differences between VS2005 web server and IIS 6.0 behavior : The default handler for any url in VS2005 is ASP.NET and in IIS 6.0 it is the file system. Since my urls are now generated, they definitely don't exist on the file system. I just had to add an ".aspx" at the end of my virtual url to get IIS 6.0 handing it to ASP.NET runtime.

Now I have my nice URLs :)

Sebastien Laban's new website

By Jerome at February 07, 2007 04:45
Filed Under: My Life

My younger brother has updated his website, with his new demoreel 2007.

Go check it out here http://www.sebastien-laban.com !

The file is not a valid Windows CE Setup file

By Jerome at February 07, 2007 04:35
Filed Under: Bluetooth Remote Control

If you've tried installing Bluetooth Remote Control on your device, and you are having trouble, such as getting this message :

The file RemoteControl.ARMV4.CAB is not a valid Windows CE Setup file

You must be working on some Windows Moblile 2003 device. I did not have the time to fix this but if you are interested in getting it to work, you can proceed as follows, if you're familiar with a CE cab file structure :

  • Expand the files on the PC using WinRar for instance,
  • Rename 0SmartBT.001 to smarbt.exe
  • Rename BTHelper.002 to bthelper.dll
  • Just put those two files on the PPC wherever you want.

You won't have a nice icon on your programs list, but at least it should help you run it.

Enjoy !


About me

My name is Jerome Laban, I am a Software developer and .NET enthustiast from Montréal, QC. You will find my blog on this site, where I'm adding my thoughts on current events, or the things I'm working on, such as the Bluetooth Remote Control Software for Windows Mobile.