VS code and bash shell scripts

The other day, I was working on moving a lot of RUN statements from my Dockerfile into separate shell scripts when I encountered the following issue:

/var/dockerscripts/installsudo.sh: line 3: sudo: command not found

This is how the shell file looked like :


apt-get update && apt-get install -y --no-install-recommends \


adduser jenkins sudo

Nothing in particular, right ?

However, it did not recognize the multiline statement character \.

So I had to change the line ending character from \r\n to \n. This can easily be done in VS code via a button in the bottom right of the editor.




Upgrading your Surface Pro to Windows 10

Windows 10 came out on June 29th at 00:00 here in Belgium which gave me about a head start of 8 hours compared to the consumers in the US, so I prepared my Surface Pro 2 (SP2) running Windows 10 Insider Preview (IP) 10240 for the upgrade.
So, here’s my story.

I wanted to do the upgrade, not a clean install, which meant I had to revert to Windows 8.1 that shipped with my Surface Pro 2. Also, I didn’t wanted to waste my Windows 10 MSDN keys on my personal devices.
A factory reset can easily be done via Settings => Update and Security => Recovery => Reset this PC => Get started => Restore factory settings in Windows 10 IP.
Unfortunately, this failed because I deleted my recovery partition that came preinstalled on the SP2.

Actually, I deleted all of them, so I could get more disk space.

So, I downloaded the SP2 recovery image from Microsoft : https://www.microsoft.com/surface/en-us/support/warranty-service-and-recovery/downloadablerecoveryimage?productId=100110237
After that I unzipped it onto a FAT32 formatted USB drive and booted the SP2 into recovery (VOL DOWN during startup)

I wasn’t able to Reset my PC. These where the errors I got :

  • The drive where windows is installed is locked
  • Unable to reset your pc a required drive partition is missing

Eventually, I ended up reinstalling Windows 10 IP 10166 to get a working version onto my SP2 and restart the process.
This time, I let the Windows 10 IP installation re-create the partitions for me.

So at that point, I had Windows 10 IP 10166 running on my SP2.

Then, I tried to revert to the SP2 recovery image again, with the same errors as mentioned above.

I rebooted the SP2, got into recovery and cleaned the Windows 10 IP partition using DiskPart : http://knowledge.seagate.com/articles/en_US/FAQ/005929en?language=en_US
After this, I was able to Reset my PC using the SP2 recovery USB image.

At this point, I had Windows 8.1 running on my system as the Microsoft gods intended when they shipped the SP2.
So, this meant I had to wait for the KB3035583 update to install and reserve my copy of Windows 10.
I decided not to wait that long and downloaded the Media Creation Tool : http://windows.microsoft.com/nl-nl/windows-10/media-creation-tool-install to start the upgrade.

I chose Upgrade this PC now to start upgrading.

Since then, everything went smoothly, I ended up with Windows 10 PRO fully activated on my SP2!
After a Disk Cleanup of Windows Updates and Previous versions of Windows, my C:\ had about 16,4GB in use!

But I wanted a clean installation of Windows 10, so I opened Settings => Update and Security => Recovery => Reset this PC => Get started => Remove Everything. After all of that, I had about 10,4 disk space in use, my version of Windows 10 PRO was activated and running smooth.

I tried to upgrade the Windows 7 ULT PC at home, but due to limited disk space (50GB SSD, 10GB free) I had no option but to clean install Windows 10 from ISO. So I created a bootable USB drive using the Media Creation Tool and booted the PC up, did the Upgrade. After doing the upgrade it was activated and genuine.
Then I did a Disk Cleanup, Reset my PC, Remove Everything.

Now I have an upgraded, clean SP2(WIN8.1) and PC(WIN7SP1) running Windows 10 PRO, activated, genuine.

I can see myself reusing the Reset this PC feature quite a lot in the future, since it takes away a lot of the effort on finding a legitimate product key and installation media to do a new clean install. The downside, is that you won’t be able to alter your hardware since Microsoft creates a hash of the machine it upgraded in order to activate it. So, I think having a store-bought copy of Windows 10 is something that can not be avoided in the near future.


Please note that both of my machines where eligable for upgrade to Windows 10 (WIN8.1 and WIN7SP1) Both of them where genuine and activated before the upgrade.





Adding content to your XAML controls / behaviors / dependencyobjects

I’m all in for clean, readable and non-redundant code. For JavaScript, C# and XAML alike.

So instead of writing XAML like this :

		<myNs:MyItem Text="Item 1">
					<myNs:Child Text="Child of Item 1"/>
		<myNs:MyItem Text="Item 2"/>
		<myNs:MyItem Text="Item 3"/>

I’d rather look at something in the likes of this :

		<myNs:MyItem Text="Item 1">
			<myNs:Child Text="Child of Item 1"/>
		<myNs:MyItem Text="Item 2"/>
		<myNs:MyItem Text="Item 3"/>

In order to get this to work for your custom XAML elements, you’ll need to specify the property that will act as the content property of the element. This can be done via the ContentPropertyAttribute.

So let’s say you have a Control, FrameworkElement or DependencyObject that you want to apply this to :

[ContentProperty(Name = "Items")] //Set the attribute and the name of the DP that holds the content
    public class MyObject : Control
        public DependencyObjectCollection Items //This property will act as the content of MyObject, this is a collection, but it can also be a DependencyObject
                DependencyObjectCollection collection = (DependencyObjectCollection)base.GetValue(MyObject.ItemsProperty);
                if (collection == null) //Initialize in case of NULL
                    collection = new DependencyObjectCollection();
                    base.SetValue(MyObject.ItemsProperty, collection);
                return (DependencyObjectCollection)GetValue(ItemsProperty);
            set { SetValue(ItemsProperty, value); }

        // Using a DependencyProperty as the backing store for Items.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ItemsProperty =
            DependencyProperty.Register("Items", typeof(DependencyObjectCollection), typeof(MyObject), new PropertyMetadata(null));

        protected override Windows.Foundation.Size ArrangeOverride(Windows.Foundation.Size finalSize) //When added to the visual tree, write a debug line of the content of this control
            return base.ArrangeOverride(finalSize);

        public override string ToString()//This is pretty obvious
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("This is a MyObject");

            int itemCount = 0;
            foreach (MyItem item in Items)
                builder.AppendLine(String.Format("This is a MyItem {0} with text {1}", ++itemCount, item.Text));
                var child = item.Child as MyChild;
                if (child != null)
                    builder.AppendLine(String.Format("And with child {0}", child.Text));

            return builder.ToString();

Now for the rest of the classes :

//A child doens't have content, just Text
public class MyChild : DependencyObject
        public String Text
            get { return (String)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }

        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(String), typeof(MyChild), new PropertyMetadata(null));
//The MyItem can have content, the contentproperty is Child
    [ContentProperty(Name = "Child")]
    public class MyItem : DependencyObject
        public DependencyObject Child //This is just a dependencyobject, not a collection
            get { return (DependencyObject)GetValue(ChildProperty); }
            set { SetValue(ChildProperty, value); }

        // Using a DependencyProperty as the backing store for Child.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ChildProperty =
            DependencyProperty.Register("Child", typeof(DependencyObject), typeof(MyItem), new PropertyMetadata(null));

        public String Text
            get { return (String)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }

        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(String), typeof(MyItem), new PropertyMetadata(null));


As stated above, this could be the XAML, since MyObject is a Control, we can add it to a Panel, a grid, for example :

                <myNs:MyItem Text="Item 1">
                    <myNs:MyChild Text="Child of Item 1"/>
                <myNs:MyItem Text="Item 2"/>
                <myNs:MyItem Text="Item 3"/>

Please note that nothing is rendered, this control doesn’t have a visual representation, however, the ArrangeOverride method is called, thus output can be found in the Debug window:

This is a MyObject
This is a MyItem 1 with text Item 1
And with child Child of Item 1
This is a MyItem 2 with text Item 2
This is a MyItem 3 with text Item 3

Some final notes, first is that a control can only have one piece of content, it can be a DependencyCollection, this allows you to add multiple elements to the control.

Also, note that Items and Child are not strongly typed, they are DependencyObjectCollection and DependencyObject respectively. This requires you to cast the content to a MyItem and MyChild. You could create your own DependencyObjectCollection, MyItemCollection, for example. But that’s a refinement for another day.

Keep on XAML’n 😉

Creating a bootable USB recovery disk for Surface Pro 2

With Windows 10 (Technical/Insider) preview emerging everywhere on the web, you might just want to do a clean install of the OS on your SP2.

I’ve tried several times in order to get it right, here’s what you need to do to create a bootable USB disk.

First off, i’d recommend a 8GB USB2.0 disk or higher, USB3.0 will speed things up tremendously.

Make sure you have the ISO of the OS you want to install, mount the ISO using your favorite ISO mounting tool, also, write down the product key.

This is a sample setup :

  • ISO to install : Windows 10 Insider Preview Build 10074
  • OS that will create the USB bootable disk : Windows 8.1 PRO
  • USB disk : 32GB USB3.0
  • Product Key Windows 10 Insider Preview Build 10074
  • Drive letter with the mounted ISO : D:\
  • Drive letter with the USB disk : E:\

These are the steps :

  1. Insert the USB disk into a Windows 8, 8.1 or 10 machine.
  2. Run command prompt as an administrator, WINDOWS-KEY + R, type ‘cmd’ press enter
  3. type ‘diskpart’ in the command prompt
  4. type ‘list disk’ to sum up the disks on your system
  5. Make sure your USB disk is shown in the list
  6. type ‘select disk X’ where X is your USB disk
  7. Now type the following commands, these will WIPE THE DISK and copy the contents of the ISO to the USB disk
    1. clean
    2. create partition primary
    3. select partition 1
    4. active
    5. format quick fs=fat32
    6. assign
    7. xcopy D:\* E:\ /s /e
  8. At this point the command prompt will start copying all of the files from the ISO to the USB disk

We’re not done yet, you’ll need to reboot the Surface Pro 2 from the USB disk. These are the requirements in order to do this :

  • You need a bootable USB disk formatted as FAT32
  • Disable secure boot

We now have the bootable USB disk, to disable secure boot, you need to enter the BIOS setting of the Surface Pro 2 like so :

  1. Shut down the SP2
  2. Hold volume up
  3. Press and release the power button to boot the SP2
  4. When the Surface logo appears, release the volume up button

You are now in the BIOS of the SP2, disable secure boot and reboot the device.

I’m not sure if you will experience this, when secure boot was disabled, the boot screen of my SP2 turned RED. You can re-enable secure boot after installing the OS.

Now to install the OS.

Turn off your SP2 (by pressing and holding the power button for 10 seconds, for example).

Boot from USB :

  1. Press and hold volume down button
  2. Press and release power button
  3. When you see the Surface logo, release the volume down button
  4. Your USB drive will start lighting up and the installation process will start

The installation footprint of a clean Windows 10 Insider Preview installation was 11GB, which is reasonable, I now have a lot more space on my disk to use thanks to a clean install! =)

Success on installing your new OS from a bootable USB drive on your SP2!

Finding Parent, Child, Children and Sibling controls in XAML for WinRT

A little while ago, I posted some solutions to common problems in developing apps for WinRT. Which I solved using Behaviors (Blend Behaviors SDK).

These approaches used a class called ControlHelper, while the functionality was sufficient, I was in need for something more thorough.

So, I’ve updated the ControlHelper to support the following functionality :

    • Find the Page of an element
    • Find the Parent based on a type of an element
    • Find the Parent based on a type and/or condition of an element
    • Find all the children based on a type and/or condition of an element
    • Find a sibling of an element, based on a type and/or condition

    Sourcecode for the ControlHelper

    Sample application on github


WinRT Multiline TextBox

I’ve tried using a RichEditBox as an alternative for a multiline TextBox, since this is a very tedious task, I’m going back to the TextBox.

In short, to create a multiline TextBox, just apply this style :

<Style x:Key="MultilineTextBoxStyle" TargetType="TextBox">
<Setter Property="AcceptsReturn" Value="True" />
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="Width" Value="Auto" />

Behaviors for Windows Apps (Windows 10)

So with the newly released Windows 10 SDK we can start migrating our current Windows 8 / Windows 8.1 / Windows Phone 8.1 apps to the new Universal App Platform or simply UAP.

I was hoping there would be a port for the current Windows 8.1 Behaviors SDK (XAML) but alas, no such thing.

In anticipation for the Windows 10 team to deliver such a library, I’ve migrated the current Microsoft.Xaml.Interactivity.dll to a class library. Which you can use to migrate your current Windows 8.x codebase to Windows 10 UAP :

How does this work ?

Well, I’ve kept the interface and class names the same, so porting should be rather easy.
You will, however, need to change the xmlns declarations from xmlns:interactivity=”using:Microsoft.Xaml.Interactivity” to xmlns:interactivity=”using:Merken.Windev.BehaviorsForTen”.

Example xaml declaration:


    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Button Content="Tap me!" Grid.Row="0">
        <Button Content="Invoke me!" Grid.Row="1">
                <core:EventTriggerBehavior EventName="Click">
                    <core:InvokeCommandAction Command="{Binding ClickCommand}"/>
        <TextBlock Grid.Row="2" Text="{Binding Clicked}"/>

Example custom behavior :

using Merken.Windev.BehaviorsForTen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace Merken.Windev.BehaviorsForTenTestApp.Behaviors
    public class ItemTappedBehavior : BehaviorBase<FrameworkElement>
        protected override void ElementAttached()
            AssociatedElement.Tapped += AssociatedElementTapped;

        protected override void ElementDetached()
            AssociatedElement.Tapped += AssociatedElementTapped;

        private void AssociatedElementTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
            foreach (IAction action in Actions)
                action.Execute(this, null);

        public ActionCollection Actions
            get { return (ActionCollection)GetValue(ActionsProperty); }
            set { SetValue(ActionsProperty, value); }

        // Using a DependencyProperty as the backing store for Actions.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ActionsProperty =
            DependencyProperty.Register("Actions", typeof(ActionCollection), typeof(ItemTappedBehavior), new PropertyMetadata(new ActionCollection()));

BehaviorBase is a abstract helper class which you can derive from, it provides the plumbing of a custom behavior, such as deriving from DependencyObject and associating the attached element.

The same goes for ActionBase.

It isn’t required to derive from these base classes, however it would speed up you development when creating new behaviors.

For your migrated behaviors, you can still use the IBehavior interface and provide the implementation yourself.

Just check out the sample application : https://github.com/merken/BehaviorsForTen/tree/master/Merken.Windows.BehaviorsForTenTestApp

I haven’t ported the Microsoft.Xaml.Interactions.Core namespace, yet. So hold yer horses.

I’ve ported the following classes from the core namespace :

  • DataTriggerBehavior
  • EventTriggerBehavior
  • InvokeCommandAction

Make sure to check out the example app : https://github.com/merken/BehaviorsForTen/tree/master/Merken.Windows.BehaviorsForTenTestApp