30 January, 2013

WPF MenuItem programmatically

I seriously don’t know what they had been smoking in Redmond when they invented the URI scheme for WPF. It’s really far from intuitive nor understandable, so if you have set out to create e.g. a ContextMenu programmatically (code over Markup XAML); you are in for a surprise!

Building an editor that required a dynamic tabcontrol (you can add/delete the tabs during runtime); I had to enable a contextmenu associated to these new runtime defined tab items. But, creating these menuitems in code (C#) is not intuitive. So, if you don’t want to spend 1½ hour hunting how to do this, here is how:

        private void NewTab_MouseUp(object sender, MouseButtonEventArgs e)
MenuItem editMnu = new MenuItem();
editMnu.Click += editMnu_Click;
editMnu.Header =
editMnu.Icon =
new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Images/edit.png", UriKind.Absolute))};

MenuItem delMnu = new MenuItem();
delMnu.Click += delMnu_Click;
delMnu.Header =
delMnu.Icon =
new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Images/cancel.png", UriKind.Absolute)) };

ContextMenu cmnu = new ContextMenu();

(rest omitted)


Note the format of the Uri-scheme “pack://applica…..”.! That guy actually points to a location within the application inside the Images folder (see below).


Ultimately, you end up with a new tab with this Contextmenu:


Who should have known…

28 January, 2013

Microsoft.Expression.Interaction.dll – where is it?

For the life of me, I could not find the interaction assembly from Microsoft. And “Googling” the matter only reveals that I was most certainly not the only one with that problem! I learned, that it is included as part of the Expression Blend SDK for Silverlight 4.


And can be found here (on a Win8 machine):
C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\Silverlight\v4.0\Libraries


URL friendlyUrls not working?

Attempting to make use of the Microsoft.FriendlyUrls Nuget package to solve a routing problem I was installing this into my application. According to all documentation you simply enable this by typing:

  public class Global : System.Web.HttpApplication

protected void Application_Start(object sender, EventArgs e)

The thing is though, that it does not work! It complains it does not know the RouteConfig class.

To make this work, you need to install an additional package (note the prerelease selection)


14 January, 2013

Check for Javascript enabled

Rather an easy solution, but still elegant. When you want to make sure the client is running with Javascript (and thus JQuery) enabled; you can basically do this using the simple <noscript> tag. Note that the #outerFrame is the entire site (main Div). By using this approach you get an entirely blank site with only the text: “You need to have javascript enabled to use this site. “. The second the user enables Javascript – the site renders normally.


form id="form1" runat="server">
style type="text/css">
#outerFrame {
display: none;
div class="noscriptmsg">
You need to have javascript enabled to use this site.
asp:ScriptManager ID="scrtMgr" runat="server" EnableCdn="true" EnablePartialRendering="true"></asp:ScriptManager>
div id="outerFrame" class="main">
……. (rest is omitted for brewity)

08 January, 2013

Stop VS from opening every file you touch!

Man, is it annoying when VS opens every single file you touch (just click it!) in the Solution Explorer? I’ve been irritated by VS opening a file just because you click it. I want it to be opened only when you want it to open. I other words I want it to open when double-clicked.

This can be changed in: Tools – Options – Environment – Tabs and Windows – Preview Tab (see screenshot).

Just uncheck the Preview Tab and you are good to go.


InRiver: Not loading your extensions?

(You really need to in the loop to appreciate the issue this post addresses). Man, I've been fighting this problem for hours before I ...