I almost expected the guy to be Canadian. :) This series of fantasy books is a masterpiece of writing. Not only it is complex of plot and emotion, but the characters are many, diverse and (most of all) different.

So far, the A Song of Ice and Fire saga, written by American author George R. R. Martin, consists of four books, the first published in 1996 and the last in 2005. At least three other books are planned in this series. The plot is a historical fantasy, but one unlike the books I've read recently. The aspects of magic and otherworldiness are rare, the bulk of the writing being about the feudal world, with kings, knights, low borns, maidens and whores, thieves, rapists and murderers, plotters and honorable men. No wonder that, lacking a lot of special effects, the story has been selected as the basis for a TV series.

But what is more important than anything is that the writing is really good. The characters are all human, with needs, desires, qualities and faults. You can't help but empathise with them, only to suffer at the cruel fate the writer bestows upon them. Not one escapes unscathed from the malice and pettiness of other people or from shere bad luck. You get to like the characters, then Martin fucks them up. I really wanted to use a more elevated language here, but it's the truth: the world he depicts seems horribly real, not a fairy tale of valiant white knights and pure maidens, but of ridiculous people grabbing lustfully whatever life offers them as it is unlikely their fortune is going to last long.

For the bad part, though, I think the author went too deep, got himself responsible for a lot of characters that he must now move forward, in gruesome detail. The fourth book became so large that he had to split it. He did so by character and geography, rather than by time, so a lot of the characters were missing from the fourth book, A Feast for Crows, and left for the fifth, but acting in the same timeline. At the end of A Feast for Crows the author explains his decision to not just split the book in the middle with a "To Be Continued" ending, and hopes for a publication of the second half in a year. That was in 2005. Ahem.

A lot of people are a bit confused by the long wait for the fifth book. Martin keeps making promises that he doesn't keep and, in July this year, he announced that A Dance with Dragons is already 1400 pages long and 5 chapters close to completion. I hope he does finish it quickly enough, although that would only prolong my suffering anyway. I am sure the fifth book will be as brilliant as the others, but then I will have to wait another 5 years for the sixth. I know TV series usually have no plot, but at least they come weekly ;)

Bottom line: The books are great, I recommend them to any lover of fantasy or even historical novels. I can hardly wait for the TV series, A Game of Thrones, as well.

and has 2 comments
While waiting for the tenth book in the Malazan Book of the Fallen saga, I went and read Prince of Nothing, by another Canadian author, R. Scott Bakker. This is a three book story, first published in 2004, about what I can only describe as a psychopath, member of a rationalizing sect, going out into the world to protect the secret of said sect.

The book is well written, although not nearly as brilliant as the Malazan series. However the subject of it is very interesting, at least from my standpoint. It concerns a human that is trained in the ways of mental manipulation, rationale and causality, something akin to the Vulcans from StarTrek, but with a very human side to it, the one that pushes one to amass power and use their knowledge to manipulate.

No wonder that the "prince of nothing" is the central character in the books, but not the main character, the role being left to a sorcerer, a man that is at the same time keeper of arcane knowledge and the scorn of ordinary humans. I can't help but empathize with the guy: basically a geek in love with a whore, while a psychopath destroys his world with insidious manipulation. ;)

There is another central character to the story, an insane barbarian, like a tortured Conan, who is both terrifyingly strong and ridiculously fragile, both a mindless warrior and a brilliant strategist. He is also, like Achamian the sorcerer, an exponent of humanity.

Prince of Nothing is a very smart book, one that can only get better as the writing skills of Scott Bakker improve. Its assets are both a scientific approach to the human psyche and a veritable intrigue of arcane powers in conflict with each other on the background of huge masses of clueless people. The plot itself is similar to the story in the Berserk manga, at least its start, where the strong warrior chooses to follow the charismatic and ambitious leader only to his doom. The moral, as I saw it, is that while we choose to live our lives with eyes closed, we cannot in good conscience pretend to deserve control over what happens to us.

I hope the series, known as "The Second Apocalypse", continues, since Prince of Nothing raised more questions than gave answers and the plot really caught my attention. A nice book that I warmly recommend.

I haven't been the most present of hosts, but then again, I haven't seen much interest for the collaboration page, with its open chat and whiteboard. Therefore I replaced the link to it with the Plugoo chat. The blog desperately needs some refactoring, but not likely that it will happend soon.

I was working on this application and so I found it easy to create some controls as UserControl classes. However, I realised that if I wish to centralize the styling of the application or even move some of the controls in their own control library with a Themes folder, I would need to transform them into Control classes.

I found that there are two major problems that must be overcome:

  1. the named controls in a user control can be accessed as fields in the code behind; a theme style does not allow such direct access to the elements in the control template.
  2. the controls that expose an event may not expose an associated command. In a user control a simple code behind handler method can be attached to a child control event, but in a theme a command must be available in order to be bound.



Granted, when the first problem is solved, it is easy to attach events in the code of the control to the child elements, but this presents two very ugly problems: the template of the control will need to contain the child elements in question and the event will not be declared in the theme, so the behaviour would be fixed as well.

I will solve the handling of events as commands by using a solution from Samuel Jack. The article is pretty detailed, but to make the story short, one creates an attached property for each of the handled events by using a helper class:


public static class TextBoxBehaviour
{
public static readonly DependencyProperty TextChangedCommand =
EventBehaviourFactory.CreateCommandExecutionEventBehaviour(
TextBox.TextChangedEvent, "TextChangedCommand", typeof (TextBoxBehaviour));

public static void SetTextChangedCommand(DependencyObject o, ICommand value)
{
o.SetValue(TextChangedCommand, value);
}

public static ICommand GetTextChangedCommand(DependencyObject o)
{
return o.GetValue(TextChangedCommand) as ICommand;
}
}

then by using a very simple syntax on the control that fires the event:


<TextBox ff:TextBoxBehaviour.TextChangedCommand="{Binding TextChanged}"/>



The problem regarding access to the elements in the template is solved by reading the elements by name from the template. In some situations, like when one uses a control as a source for a data control (like using a TreeView as the first item in a ComboBox), the approach will have to be more complicated, but considering the element is stored in the template of the control, something like this replaces the work that InitializeComponent does inside a UserControl:


[TemplatePart(Name = "PART_textbox", Type = typeof (TextBox))]
public class MyThemedControl : Control, ITextControl
{
private TextBox textbox;

public override void OnApplyTemplate()
{
base.OnApplyTemplate();
textbox = Template.FindName("PART_textbox", this) as TextBox;
}
...


The code is pretty straight forward: use the FrameworkTemplate.FindName method to find the elements in the OnApplyTemplate override and remember them as fields that you can access. The only weird part is the use of the TemplatePartAttribute, which is not mandatory for this to work, but is part of a pattern recommended by Microsoft. Possibly in the future tools will check for the existence of named elements in the templates and compare them against the ones declared in the control source.

The code of a demo project can be downloaded here.

Some other technologies I have used in the project:

  • the RelayCommand class, to make it easier to defined ICommand objects from code without declaring a type for each.
  • the AccessKeyScoper class that allows an IsDefault button to act locally in a panel.

If you google the net for using visual effects in WPF you are very likely to hit BitmapEffects. Well, bad news, BitmapEffect is obsolete and broken in WPF4. Instead you have Effect. The idea is to write (or download) a custom Effect for the things one would normally do using the slow (but easy to use) BitmapEffects. Also, the BitmapEffectGroup doesn't work anymore and has no alternative in WPF4. Bummer! According to Dr. WPF, the framework will try to automatically translate the older BitmapEffects to the new ones. That applies for BlurBitmapEffect and for DropShadowBitmapEffect with a Noise level of 0, for the others... you are on your own.

There were 5 default BitmapEffect classes in WPF3:
  1. BlurBitmapEffect - the WPF4 alternative is BlurEffect
  2. OuterGlowBitmapEffect - the WPF4 alternative in the Microsoft article is BlurEffect, but I have found that it can be replaced by DropShadowEffect with ShadowDepth set to 0
  3. DropShadowBitmapEffect - the WPF4 alternative is DropShadowEffect
  4. BevelBitmapEffect - the WPF4 alternative is a custom class inheriting from Effect.
  5. EmbossBitmapEffect - the WPF4 alternative is a custom class inheriting from Effect.


I found this project when googling to a simpler way of building ShaderEffects: WPF ShaderEffect Generator. Also, a discussion about a Bevel ShaderEffect here led me to this WPF shader library, but it's last release date is somewhere in March 2009.

I am using this WPF control that looks like a headered panel. On the header there is a menu, a button and then, underneath, some content that could be anything. I had this request that, when using the Tab key to navigate, the focus should first come to the button, which is not the first control in the header, then jump to the controls in the content and then jump back to the menu. In other words, to make the menu the last controls that can be reached via the Tab key inside this WPF control.

Well, in WPF there is this class called KeyboardNavigation which has some very useful attached properties: TabIndex (which defaults to int.MaxValue) and TabNavigation (which defaults to Continue). As in Windows Forms, one needs to set the TabIndex to control the navigation order, but the TabNavigation property makes it a lot more versatile and clear as well. In my case, I had to do the following:
  1. Set the entire panel control to KeyboardNavigation.TabNavigation=Local. That allowed me to control the tab index inside the control, otherwise the TabIndex value would have been global to the window
  2. Set the TabIndex of the button to 1. That made the button the first thing to be selected in case I use Tab to navigate in the panel
  3. Set the TabIndex of the content to 2. This set the controls in the content as the next controls to be accessed via the Tab key
  4. Set the TabNavigation value of the content to Local. Without this, the TabIndex value would have made no sense. First of all the content panel has IsTabStop to false and, second, any control inside it would have int.MaxValue set as TabIndex which would work globally in the main control.


This example should make it clear how to use the KeyboardNavigation properties. There is one more, called ControlTabNavigation, which has a misleading name and an ambiguous description. It is not related to a control, the Control in the name comes from the Ctrl key. In WPF one can use Ctrl-Tab to navigate an alternative order thus allowing, in this case, to go directly to the menu, then the button and then the controls in the content area.

I was trying to use a static class of attached properties that I would use inside my WPF control templates, so that every time I need to change them I would only use a setter, not copy paste the entire template and make minute changes. It worked great and I recommend this solution to everybody. So after the refactoring of my control I was shocked to see that in the production application, all my attached properties were throwing binding errors!

The solution was to explicitly use the Path= syntax in the bindings.

{Binding Path=(namespace:ClassName.Property)...
not
{Binding (namespace:ClassName.Property)...

The strange thing is that in the test application everything worked great, so what went different? Apparently the problem is that IXamlTypeResolver (used in PropertyPath) is not finding namespaces unless already registered, as explained here by Rob Relyea. The dude with that Lovecraftian name is the program manager for the WPF & Xaml Language Team.

So if one uses the namespace of the attached property before in some other context or by using the verbose syntax before, it works even with the Path keyword omitted. Not really sure why the verbose syntax works differently though.

Many a time I want that textblocks that get trimmed to display their text as a tooltip. For that, I would make a trigger to set the Tooltip value to the Text value if the textblock has been trimmed. The problem is that there is no property that shows if this is the case.

Googling a bit, I found this article, which apparently works, but also has some problems, as reported by many commenters. Even if it would have worked perfectly, my scenario is too simple to need all that code.

The idea of the original post is simple and I like it, the problem being that convoluted method that computes the width of the text in the textblock. Why would I want to redo all the work that is being done by the framework itself? The width of a textblock with TextWrapping NoWrap should be textBlock.Measure(Size(double.MaxValue,double.MaxValue)). I am sure a more complex scenario can also be serviced by this method, if the height is taken from the TextBlock, but I don't need it.

So here is the entire class, using my measuring method:
public class TextBlockService
{
static TextBlockService()
{
// Register for the SizeChanged event on all TextBlocks, even if the event was handled.
EventManager.RegisterClassHandler(typeof (TextBlock),
FrameworkElement.SizeChangedEvent,
new SizeChangedEventHandler(OnTextBlockSizeChanged),true);
}

public static readonly DependencyPropertyKey IsTextTrimmedKey =
DependencyProperty.RegisterAttachedReadOnly(
"IsTextTrimmed",
typeof (bool),
typeof (TextBlockService),
new PropertyMetadata(false)
);

public static readonly DependencyProperty IsTextTrimmedProperty =
IsTextTrimmedKey.DependencyProperty;

[AttachedPropertyBrowsableForType(typeof (TextBlock))]
public static Boolean GetIsTextTrimmed(TextBlock target)
{
return (Boolean) target.GetValue(IsTextTrimmedProperty);
}

public static void OnTextBlockSizeChanged(object sender, SizeChangedEventArgs e)
{
TextBlock textBlock = sender as TextBlock;
if (null == textBlock)
{
return;
}
textBlock.SetValue(IsTextTrimmedKey, calculateIsTextTrimmed(textBlock));
}

private static bool calculateIsTextTrimmed(TextBlock textBlock)
{
double width = textBlock.ActualWidth;
if (textBlock.TextTrimming == TextTrimming.None)
{
return false;
}
if (textBlock.TextWrapping != TextWrapping.NoWrap)
{
return false;
}
textBlock.Measure(new Size(double.MaxValue, double.MaxValue));
double totalWidth = textBlock.DesiredSize.Width;
return width < totalWidth;
}
}


This would be used with a trigger, as I said at the beginning of the post:
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextTrimming" Value="CharacterEllipsis"/>
<Style.Triggers>
<Trigger Property="Controls:TextBlockService.IsTextTrimmed" Value="True">
<Setter Property="ToolTip" Value="{Binding Text,RelativeSource={RelativeSource Self}}"/>
</Trigger>
</Style.Triggers>
</Style>

Today a power outage screwed something in my Visual Studio installation. For the life of me I couldn't figure out what went wrong and I also didn't have the time to properly investigate. The issue appeared when I restarted the computer, ran Visual Studio 2010, loaded a project (any project) and tried to compile. Invariably, an error would prevent me from building the project:Error 22 A problem occurred while trying to set the "Sources" parameter for the IDE's in-process compiler. Error creating instance of managed object 'Microsoft.VisualStudio.CSharp.Services.Language.Features.EditAndContinue.EncState' (Error code is 0x80131604). Application.

I have tried disabling Edit and Continue, I've tried to disable the Exception Assistant and also I've re-registered the dlls in the Visual Studio 10.0/Common7/IDE folder, all to no avail. Even worse, it seemed as I am the only person on Google (yay!) that got this error so I couldn't find a quick no effort solution (boo!). The error code 0x80131604 stands for HRESULT COR_E_TARGETINVOCATION, or a TargetInvocationException, which is thrown by methods invoked through reflection. So that is that.

The solution was to reinstall Visual Studio. It took half a day, but it fixed it. If you have met the same issue and you found a quicker way, please leave a comment.

and has 0 comments
I was posting a while ago about the first album from Hole's bassist, Melissa Auf Der Maur. I found that the music had a haunting femaleness in it and sounded pretty cool. She has recently released her second album Out of Our Minds and my opinion is... that they were! The songs are lame, like a really wattered out version of the first. Lady, if you don't feel like it, wait until the muse graces you with her presence, don't just write crap because you have a deadline. (Let me do that, ahem...)

Moving on to Linkin Park. A refreshing mixture of hip hop and rock, their first albums (Hybrid Theory and Meteora) made them famous. If you don't count the collection of remixes of their previous songs, their third album, Minutes to Midnight, was released after some time had passed (period during which Mike Shinoda was writing hip hop like crazy and the other guy... well, nobody knows what he did), had some environmental messages, some slow music, maybe some Michael Jacksony save the world songs... It pretty much sucked, but it was also ok. I mean, if you want to mellow down a little, just to try it on, why not? So now I got reminded of them when I accidentally saw Transformers and the theme of the film was sang by Linkin Park and called New Divide. It sounded kind of cool, something that resembled their first albums, so I got their latest album, A Thousand Suns, and tried it on. Long story short: it sucked. There were some cool songs, like Wretches and Kings, or Blackout, but overall, it was a whiny piece of crap. Dude! It's called ROCK, you're letting a Japanese hip hopper make you look like an emo kid trying to sing for the highschool prom.

Ok, now for some of the better songs on these albums:

Melissa auf der Maur - Out of Our Minds



Linkin Park - Wretches and Kings

So I have returned from the holidays, but I have still a ton of stuff to organize before I get my mojo back. I will probably start writing entries from next monday, featuring the holiday to Greece, books I've read, TV series that I am watching and, hopefully, something related to programming, too :)

However, I have amassed a few small things that I wanted to say and are minute enough to not deserve their own blog post, so here are some of them:
  • I have watched the British TV mini series called The Deep. It stars lovely Minnie Driver, but the show is utter crap! I couldn't believe how bad it was. So, don't watch it!
  • Internet Explorer 9 beta was released and it is downloadable. However, when trying to install it at home it said I cannot install IE9 on a Windows XP machine and I must upgrade the operating system. Verboten! Here is a hearty Fuck you! from me, Microsoft. When are you going to get that no one prefers Windows 7 to XP?
  • I've finally watched The Expendables. Imagine one of those really low budget TV movies with heroes killing faceless bad guys in huge explosions, only with known people in the underdevelopped and badly written roles. Fail!

and has 1 comment
While looking over Reflector-ed Microsoft code I noticed an attribute called FriendAccessAllowed. I googled a little and I've come up across something called Friendly Assemblies. Basically you want that your code marked as internal be visible to other assemblies that you specify. This way you restrict access for other people, but you don't need to place all your code into a huge assembly.

Microsoft tells us that to do that for .NET you need to use InternalsVisibleToAttribute to make assemblies be friends in either a signed or an unsigned way.

All nice and all, but there is no mention of this FriendAccessAllowedAttribute class. All I could find is a Microsoft patent called Logical Extensions to Intermediate Code, which says extend the runtime's notion of friend assemblies with a "FriendAccessAllowed" attribute, and only include internal methods marked with this attribute in the reference assembly (instead of known implementations in which all internal methods are included in the assembly).. In other words, specify explicitly which of the internal members you want exposed to your friends.

There is another question about this on StackOverflow, which says as much, as well, but nothing actually usable.

As far as I can see, Microsoft uses this in the WPF and Silverlight frameworks only and the funny thing is... the attribute is internal. :)

If you search the net for a skinnable application, you get a lot of answers and pages that seem to hit the spot right on. If you are looking for a skinnable control library, though, the hit count drops considerably. This post is about my adventures with resource keys and the solution for a problem that has plagued me for more than a day of work, plus some weird behaviour that I have as yet no explanation for.

The article is pretty long, so here is the short and dirty version:
  • Do not use Colors as dynamic resources, use Brushes
  • If you want to use resources from a theme dictionary outside the assembly, you must give them keys of the type ComponentResourceKey
  • The type you use in the constructor of the ComponentResourceKey class or in the markup extension of the same name must be in the same assembly where the resource is!


The scenario is as follows:
  • there is an application that needs to change some of its visual characteristics dynamically during run time
  • the application uses a custom control library
  • other applications/modules should use the same themeing mechanism
  • other applications will use the same control library


The solution seemed simple enough:
  • create a static class to hold the string keys for the resources I want to define dynamically
  • create a shared resources dictionary in the controls theme, using those keys
  • use the shared dictionary in the controls theme
  • create another shared resources dictionary in the applications, or use only the ones already defined in the control library
  • use the application shared dictionaries in the application styles
  • programatically add/remove resources directly in Application.Current.Resources to override the already defined resources


I have tested this solution in a not very thorough manner and found it working. Of course, some of the problems needed solving.

The first issue is that theme level resources are not found from outside the assembly unless defined using a ComponentResourceKey as the key of the resources. This special class receives two parameters in the constructor: a type and an object that is a "regular" resource key. So instead of using a string, as one would probably use in an application style, you use a component resource key that receives a type and that string. A small test confirmed that a resource is not found at the application level using FindResource if only defined with a string as key and that it is found if using a ComponentResourceKey.

The second issue was that in order for a resource to be dynamically changed at runtime it needed to be defined as a DynamicResource, not a StaticResource which is only resolved at compile time. Not a huge problem. However, if one has defined some brushes in the control library and then referenced them in all the styles, then it would also work to redefine those brushes to use colors dynamically, and then all one has to do is change the colors. That would also prove advantageous if one needs a variety of brushes using the same colors, like gradients or some lighter version of the same color.

This leads to Problem number 1: Dynamically changing Color resources worked for foreground brushes, for background brushes, but not for border brushes! So you have a textbox and you define Background, Foreground and BorderBrush properties using StaticResource on brushes that themselves define their Color as a DynamicResource. You change the colors (adding new resources at the application level of the type Color) and you see the Background and Foreground changing, but the border staying unchanged.

I have no idea why that happened. Some information that I got researching this problem was related to Shared resources, but changing the shared status of brushes or even colors to true or false did not change anything. Another idea was that his was related to their Frozen status but, as there was no difference between the Foreground and BorderBrush brushes (I even used the same brush at the same time on both properties), I've decided that it wasn't the case.

BorderBrush is a dependency property belonging to the Border element, while Foreground and Background belong to the TextElement and Panel elements, respectively, and other elements add themselves as owners to them. In the case of the Border element that I have tested this weird behaviour on, BorderBrush is its own dependency property, while Background is the Panel.BackgroundProperty. I also thought that it may have something to do with FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender, but both properties are registered with this flag.

After some searching, I found that the Border element caches internally Pen objects that are used to render the different border sides. They use the same brush as the border, though, and so, even if this is the best candidate for the cause of the problem, I still don't know what the hell was going on.

The solution for this problem was (to my chagrin) to use the brushes themselves as dynamic resources. Well, it was a setback, seeing how the resources I want to change are colors and now I am forced to create brushes and, thus, stain this process with the responsibility of knowing what kind of brushes are needed for my controls and applications, but I could live with it. After all, that was all WPF stuff, so I could separate it at least from the static class holding the keys of the characteristics I wanted to change dynamically.

Problem number 2: using as a key in XAML a class with a long name which uses a constructor that receives a type and a static constant/property of a class is ugly and unwieldy. The solution for this problem was to create another static class that would hold the keys for the brushes. Each brush would have a property in the class that returns a ComponentResourceKey object that uses the classes own type as the first parameter and the constant string key from the static string key class.

That effectively changes stuff looking like {DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type UI:ResourceScheme},{x:Static UI:ResourceScheme.ControlBackgroundKey}}} to {DynamicResource {x:Static WPF:ThemeResources.ControlBackgroundBrushKey}}. Still a mouthful, but manageable.

Problem number 3 (the big one): it doesn't work! The brushes I so carefully created in the theme are not getting set in the controls, not the mention the application. What confounded the issue even more is that if I changed DynamicResource to StaticResource in the control templates I would see the brushes rendered correctly. I wouldn't be able to change them dynamically afterwards, but how come StaticResource works and DynamicResource doesn't!? Stranger still, adding/removing resources with the same key in the application resources dictionary (the mechanism that was supposed to dynamically change the aspect of the application) worked! Everything was working perfectly, and only the default brushes defined in the theme were not loaded!

The solution for this was (after hours of trial, error, googling, suicidal thoughts and starting all over again) to use a type from the control library in the ResourceComponentKey constructor! You see, I had placed both static key classes in a separate assembly from the control library. Moving the WPF related resource key class in the control library fixed everything!

Now, you may be wondering why that worked, and so do I. As I see it, if you define a template and a brush in a theme and the template is loaded and applied, then the brush should also be loaded. If FindResource did not find the brush, then it must be that either the brush was not loaded due to some internal requirements of the ResourceComponentKey class or that it was loaded and then the key I was using was different from the one I was using when asking for it or, as Akash Kava tried to explain to me on StackOverflow, it will only find in the resource dictionaries of its own logical parental tree.

I have dismissed the second option, as the ComponentResourceKey has an Equals override that simply compares type and key. There cannot be two instances of the same type and the key is a string constant, so there should be no ambiguity on whether two resource keys are equal.

What remains are that either the ComponentResourceKey class messes things up or that the resources using resource keys are placed in "logical trees" based on the target type of the ComponentResourceKey. I have looked for the usages of the ComponentResourceKey class and all I could find was something in a BaseHashHelper that seemed related to ItemsControl or CollectionView, so I don't think that's it. I also looked at the implementation of FindResource, but found nothing that I could understand to cause this.

As a funny side note, as I was going about this task I was trying to get inspiration from the way the SystemColors class worked. The resource keys related to colors that were returned were not of the type ComponentResourceKey, but of SystemResourceKey, both inheriting from ResourceKey nonetheless. I have noticed no significant piece of code in the (of course internal) SystemResourceKey class, however I did find code in FindResource that checked if the key is of type SystemResourceKey and did something with it. Nice, Microsoft! However, that was not the cause of the problem either.

After knowing what to look for, I did find on the Microsoft article about the ComponentResourceKey markup extension that The TypeInTargetAssembly identifies a type that exists in the target assembly where the resource is actually defined. In the article about the ComponentResourceKey class, they say If you want an easily accessible key, you can define a static property on your control class code that returns a ComponentResourceKey, constructed with a TypeInTargetAssembly that exists in the external resource assembly, and a ResourceId. Too bad they hid this information in the Remarks section and not in the definition of the Type parameter.

Congratulations if you have read so far! You must be really passionate about programming or desperate like me to find an answer to these questions. I hope this article has enlightened you and, if not, that you will find the answers and then get back to me :)

and has 0 comments
I have been waiting for this game for 12 years, just like everybody else, but not for the usual reasons. I like the Blizzard stories. I liked the Starcraft tales of the first game and I absolutely loved the Warcraft III plot. I was expecting something glorious this time. Well... I was kind of disappointed. The story is pretty linear, with cowboy characters and dialogues seemingly stolen directly from the propaganda in Starship Troopers.

But first, a word from our sponsors :). The campaign has a secret mission. Read about it before starting the single player game. So even if you have a Queen of Blades nagging you talking a walk around the base and buying her Xel'Naga artifacts, don't rush the Media Blitz mission. ;)

I have this old Sempron 2500+ with 1Gb of RAM. The game, at the lowest possible settings, was snail paced. One needs memory for this baby. I am not blaming Blizzard for my laziness in buying a computer, but it seemed to me that all the slowness came from reasons that could have been addressed. For example the game (as it should) remembers correctly every keystroke and mouse click in battle. However, in the HUD or in the game menu, one has to wait for the buttons to light up before clicking, and then keep pressing until the button lights up the second time. In game, the greatest slowness came from special effects that were not related to the game play. I understand a suspended nuke over a flowing lava fountain might exert the CPU of a computer, but the animation itself could have been scaled down to an animated GIF for crying out loud. The cinematic animations were pretty nice, and I loved how when I ran out of resources the film would not freeze, instead the characters would wait for the next part of the dialogue, breathing and moving their eyes. But still, since there is no interaction whatsoever from the user, can't you precache it into a movie? One that can be played on any computer and has the video in sync with the audio?
So yes, the game is running slow on my computer, but I feel that it could have worked a lot better with only some minor tweaks of the in game interface.

The in game interface is pretty nice, completely 3D and the map itself is 3D and some units (a precious few) can take advantage of that, like hopping jet packed soldiers or air-ground transforming machines called the Vikings). However, the game play is almost identical to the first game, so the 3D feels kind of pointless. There are camera zoom and rotation abilities, but the zoom out is limited to a pretty low setting and the zoom in is kind of pointless unless you have female units to properly look at :)

The units of the game are interesting enough. The old units have been morphed, replaced, removed, and new units were added. For the humans are multiple types of turrets, including machineguns on the bunkers, air units dropping turrets and a special mind control tower that permanently captures zerg units. The Goliaths are still there, but also a more heavy, ground focused Thor unit is available. There are multiple soldier units other than the Marines and Firebats, like hopping and grenade launching units. It is funny though, most human soldiers and vehicles are focused on attacking only ground units. The air units have been reinvented. There are small troop carriers that can heal units, really big Hercules troop carriers, the Battlecruisers have an upgrade that allows them to attack air units with missiles, the Valkirie is gone, but it was replaced by the Viking, a sort of transformer unit that can fly and attack air units or transform into a walking robot that attacks ground units. There are two types of science vessels and they repair mechanical units instead of firing EMP pulses. There are two types of ghosts, too.

The Zerg have been transformed, too, as well as the Protoss, but I can't really address this issue until I play some multiplayer games to see it from all perspectives. And yes, I guess you already know by now, but I will tell you anyway: after 12 years of waiting, you only get the human campaign. The Zerg follows, then the Protoss, probably in expansions to the game.

There is a mini campaign with the protoss, where any two templars (dark or light) can be morphed into an Archon, but I have seen no trace of the Dark Achon. I really loved that unit. I hope they didn't remove it. Also the zerg overlords need to transform into Overseers in order to be observers; they lose the ability to transport and to pour creep from the air (yeah, really cool) and instead have the ability to spawn banelings, creatures that attack ground units and transform into the same low level unit they encounter, like a zealot or marine or something like that. I know this because, while missing the Dark Archon, I really loved the human zerg capturing beacon tower :) I haven't seen any lurkers, either. I liked them, too. Instead there are some walking buildings that burrow in the creep and become normal ground turrets. Maybe that's the only way to build ground turrets now.

There were some real innovations to the game. The units that can hop to high ground is one of them. The way SCVs are repairing nearby structures and mechanical units without someone having to tell them to do it is something that I really liked. Also you can place a building over ground covered by your own units and they will just move out of the way. You also get useful alerts, like idle SCVs. I liked that as well. There is a special human building where one can call mercenaries, specialized unit squadrons that have extra health and deal extra damage. Also, in the story, there are research points that you earn and use them to select one of two choices in a list of pairs of technologies. For example you can choose to slow zerg units instead of capturing them with the beacon, you can choose stronger bunkers instead of machine gun equipped, etc.

That being said, there are still ridiculous ways in which groups of units interact. You can't easily tell a group of medics to accompany and repair a marine unit. If you select them all and attack, the medics will heal the marines, but if you tell them to move, they won't! If you select multiple air and ground units, there is no way to tell them to clump together. The air units will just go over and die, while the ground units use the scenic route. Units do move out of the way of other moving units, but only for a while, sometimes getting into infinite loops. As in the previous game, the forward line of an attack group doesn't know to move a little forward to let the back like be in attack range and heavily hit units don't really have any way to retreat while others are covering.

So yes, I guess one can enjoy the game as the one before, but I am the kind of guy who likes automatic transmission, cars that park themselves and, hopefully in the near future, drive themselves. I would have created an entire option panel that described how units ought to behave.

Now for the story. Spoilers alert! If you want to play the game and see the story unfold, stop reading!.

The sector is mostly occupied by humans. Mengsk has overthrown the government and became emperor, one that is even more brutal and oppressive than the one before. In the process he betrayed his partners: Jim Raynor and Sarah Kerrigan. Raynor is now the leader of the resistance, while Sarah Kerrigan was abducted by the Zerg, transformed into an infested version of herself and has since taken over as the leader of the Zerg, after the Protoss have destroyed the Overmind.

So Raynor is doing mischief trying to get to Mengsk, while the Zerg appear in the sector and start taking over human worlds. The Protoss couldn't care less. They occasionally purge worlds of Zerg (by destroying the entire planet, inhabited or not) or hold up in sacred locations, bent on stopping anyone from taking their precious holy artifacts.

You see, the Protoss are believers in the Xel'Naga, their creator gods. Well, what do you know? The Xel'Naga actually exist, they created the Protoss and the Zerg and now they are returning. Looking like hybrids of Protoss and Zerg, they have shields, they can heal really fast and can corrupt zerg units into becoming their slaves. Probably tired of waiting 12 years to get the second Starcraft game, they are pretty pissed and want to corrupt all the Zerg into destroying all life in the sector, then commanding them to kill themselves, thus ending all life.

Raynor is here to save the world so, with a little premonitory help from his friends Zeratul and Tassadar, he sees what the Xel'Naga plan and sees that the entire future depends on him NOT KILLING Kerrigan. She alone can do something against the Xel'Naga. We also learn that the Overmind was under the control of the Xel'Naga all the time and it created the Queen of Blades from Kerrigan as a solution to its enslavement, thus proving great courage. Poor Overmind :'(

Therefore, the purpose of this campaign is to get to the Queen of Blades and use an ancient Xel'Naga artifact to purge the Zerg out of her. Badly enough, Infested Kerrigan is not the sexy babe she was in the first franchise, instead she is some afro-mongoloid with bad skin and shiny eyes, so I was highly motivated to see her brought back to normal.

The story has three choice points, which can slightly alter the plotline. One is when the world where you relocated some humans you saved gets infested. Protoss units come to purge the world and you can have the choice of purging the world yourself or fighting the Protoss to stop them. Later on, one can choose whether to use Ghosts or Specters. Specters are a slightly insane version of the Ghost created by one of Mengsk's secret programs. Then, on Charr, you can choose to destroy the Zerg Nydus worms or their air units. I was also mentioning a secret mission, found if destroying a conspicuous building in the Media Blitz mission.

Obviously, I purged the humans and kept the spectres. I killed the Nydus worms, too, but I think that's clearly the more sensible solution when you have the capture beacons.

!!! Uberspoilers !!!

The campaign ends with Raynor untransforming Kerrigan, killing Tychus who has been sent to kill her, probably by some Xel'Naga influenced human group (I dare say it would have been stupid for Mengsk to ally with the Xel'Naga, but he is a likely culprit) and purging Charr of all Zerg.

Ok, there are also some cheats that can help you end the game faster. You won't get any achievements if you use them, but then again, you need to play the uncracked version to use achievements, so the hell with them.

and has 0 comments

You know when you are playing some famous game you get millions of pages discussing strategies and solutions to in-game problems? Well, if you think about it, all those pages could be brought together and bound in something like a book. Why not write StarCraft for Dummies or Professional Warhammer 40000? And with that in mind, how would you feel about a book whose entire purpose is discussing Pac-Man?

Curious yet? You can check it out here! It writes about the algorithms used in the game, the tips and tricks for playing, even the different personalities of the four killer ghosts! Everything complete with pictures, diagrams and YouTube videos!