Archive for July, 2008|Monthly archive page

Problem when you blog about source code

In Personal on 29 July, 2008 at 7:00 pm

The 2 main issues that will bog you down is that:

  1. how do you get the source code to indent properly
  2. and how do you get the style to show up properly, specifically the line spacing, the color for keyword and so on

I know that it can be solved by defining some CSS code but do you have to do that for every site that you change to?

Of Dungeons and Dragons

In Gaming on 27 July, 2008 at 10:10 pm

It is now the 4th edition.  I’ve just received the collector’s edition of this latest edition which I’ve ordered from  Everything has changed!  No Druid in the latest version of Player’s Handbook!  But I must say that it is now much simpler and much straight forward to really enjoy the game itself.  You just needs to remember one core mechanic to really play the game, roll one 20 sided dice, add any modifier to the dice roll and if the result is higher or equal to the difficulty rating, you succeed in what you want to do (as in to hit that Ogre Mage, to climb that slippery wall or even to dodge the fiery breath of that ancient Red Dragon).

Each character level has been sub-divided into 3 tiers.  The first is the Hero tier, this means that even a level 1 character is considered as a Hero, player character is different from those run-of-the-mill non player character.  You’re a Hero once you start to play D&D, how cool is that?  After playing for 10 level and killing some dire monster, starting at level 11, you will begin the next tier, that of the Paragon (which means a model of excellence or perfection), with the additional power that you’ve gained, you can now fight more powerful monster, accomplish more impossible task and move yourself nearer to the next tier.  And when you reach level 21, you are now a legend and you embark on your Epic (the last tier) journey.  Now you know that you can reach any goal that you set, even that of becoming a God.

I’ve been playing the 3rd Edition with Neverwinter Nights 2 and I hope that soon I can play the 4th Edition on my computer.  I just can’t wait.

To bind or not to bind (Part 2)

In Programming on 25 July, 2008 at 7:00 am

To expand on what I’ve mentioned in my previous post.  The list box declared in XAML will look something like this:

    ItemTemplate="{DynamicResource CheckListTemplate}"
    ItemsSource="{Binding Source={StaticResource CheckedSource},

Under the <Windows.Resources>, the data template will be declared as:

<DataTemplate x:Key="CheckListTemplate">
  <StackPanel Margin="0,3,0,2" Orientation="Horizontal">
    <CheckBox IsChecked="{Binding Path=IsShown}"/>
    <TextBlock Text="{Binding Path=Name}"/>

At the same place or inside a style XAML’s ResourceDictionary, the data source is declared as:

<source:SColorList x:Key="CheckedSource"/>

Inside the C# file the classes are declared as:

    public class SColor : INotifyPropertyChanged
        private string displayName;
        private Color clrShow;
        private bool permanent;
        private bool show;
        public bool IsShown
                show = value;
                return show;
        public string Name
                displayName = value;
                return displayName;
        public event PropertyChangedEventHandler 
        private void OnPropertyChanged(String info)
            if (PropertyChanged != null)
                PropertyChanged(this, new 
    public class SColorList : 

Under an initialization method, you should then do the following:

        SColorList colorList = 

After that is done, the binding is complete and you can then add data item into the colorList and it will show up in the list box control.  And the best thing is your designer can do “magic” on the DataTemplate.

To bind or not to bind

In Programming on 24 July, 2008 at 7:00 pm

One feature of WPF is to bind a data providing class to a data receiving control, Microsoft decided to call it data-binding.  Data-binding is a strange topic for developer coming from C++, MFC background.  For them when you create a control, you will then needs to manually write code to add data to the control, there is no magic there.  In WPF, magic is created once you use data-binding, when the data providing class refresh with new data added, the control will automatically get updated to show all the new data items.  To accommodate developer who don’t understand much about data-binding, WPF with C# still provides the traditional way of adding data to a user control.  This is OK until you bring in the designer.

Let’s see an example.  For some reason WPF does not support checked list box, however customizing one from the vanilla ListBox is not that difficult.  I’ve seen developer recommending that since list box can take any control item, thus when you add item, just new a CheckBox item, add that to the ListBox and you have a checked list box.  This is correct as long as no visual changes is going to be done to the CheckBox item.  If you are going to change the square check box into something more fanciful and you want your designer to do that for you, you’re out of luck.  Since these check box items are created in the code and not on the XAML, designer can’t see it in the Microsoft Expression Blend and thus can’t change them.  Global styling you say?  What if in your UI there is another check box item and you don’t want them to look the same?

Data-binding can help you here.  Create a DataTemplate in your XAML file, bind it to the ItemTemplate of the ListBox control and bind the ItemSource to the data class which inherit from the ObservableCollection class.  Now you can customize the DataTemplate to consist of a check box and a text label and since this is created in a XAML file, designer can see it and thus can reshape to whatever she wants.

Finally made the change

In Personal on 24 July, 2008 at 7:00 am

After using iblog for about 1 and a half year, I’ve finally decided to join in the flow and choose the popular WordPress type of blogging service.  One problem with iblog is that it is not up to date with the trend in blogging and thus not even tag is supported, however, it allows user to customize the theme (note CSS, not just changing the template) without any other added cost.  But the cons finally outweigh the pros and I’ve finally made the change.


Technorati Tags: ,,