State of Silverlight on my Blog - Edition 2013

Alright, I’ve been blogging about this before, but Silverlight support is no longer increasing. At least when I’m looking at the stats of my blog. The last couple of years the amount of users on my blog that had support for Silverlight was increasing. Though it isn’t anymore it seems.

Important: I’m comparing the stats I have on my blog, this is of course not comparable with the web, nor a statement on Silverlight in general!



I’ve been comparing the visitors who have support for any version of Silverlight, this percentage is lower in 2012 than it was in 2011. I think that this is something we could have been expecting, because there are no mobile devices, phone and tablet, that support Silverlight in their browser. Tablets are becoming more and more common these days, so more of the visitors will use tablets to visit my blog.

For me, my conclusion is to get rid of the Silverlight Tag Rotator on my page, never saw it? You’re probably running without Silverlight.

Google Analytics now also on your Windows Phone 8 app in 1 minute

Yes today I released the Google Analytics NuGet package that supports Windows Phone 8. It’s part of the same NuGet package of the version for Windows Phone 7. I’ve heard that creating an app account doesn’t work any longer with Windows Phone apps, though you can fake it into a website. But for the detailed three steps I recommend reading my previous post. The fast track?

Open the NuGet Package Manager Console and type:

Install-Package MSAF.GoogleAnalytics
Have fun!

Google Analytics Real Time tracking for Windows Phone, who’s using my app right now?

Interested to see what happens right after you send everyone a push notification? I am!

At first I thought it wasn’t possible to do Page tracking from within the MSAF + Google Analytics. But after a little bit of investigation I saw that it was always overwritten by MSAF, a small modification made it possible.

The NuGet Package I created (now updated) has new methods to track the page on the AnalyticsTracker helper-class.

public interface IAnalyticsTracker
    void Track(string category, string name);
    void Track(string category, string name, string label);
    void TrackPage(Uri pageUri);
    void TrackPage(string page);

I now have a simple extra call inside the OnNavigatedTo methods on the Page.

protected override void OnNavigatedTo(NavigationEventArgs e)
    var analyticsTracker = new AnalyticsTracker();

And the result with testing both my emulator and on the phone itself was this image.


Try it out yourself.

Book review: Microsoft Silverlight 5 and Windows Azure Enterprise Integration

Disclaimer: I received a copy of this book from Packt Publishing.

The author, David Burela, though I didn’t hear about him before seems to be well known in the Australian community.

When you look at the contents of the book it looks like it’s covering the main integration parts with Windows Azure.

- Hosting Silverlight Applications in Azure
- Using Azure Queues with Silverlight
- Accessing Azure Blob Storage from Silverlight
- Storing Data in Azure Table Storage from Silverlight
- Relational Data with SQL Azure and Entity Framework
- RIA Services and SQL Azure
- Exposing OData to Silverlight Applications
- Application Authentication

The author expects you to already have some Silverlight knowledge and thus won’t explain the Silverlight parts in too much detail. My experience with Windows Azure is small, which makes me probably part of the target audience. The introduction helps you understand what Azure is, a good refresher for me. After that, chapter after chapter there’s an explanation on how to integrate Silverlight with the backend, running on Azure. All in all it stays very basic and a couple of times it refers to some MSDN pages for the details. Though I agree that copying information that’s already on the web is probably not a good thing, I was reading the book on the bench and this means, no details for me at the time. I would rather have a book that is complete and puts these kind of additional parts in an Appendix.

In the end I didn’t feel satisfied. Most of the integration was more like, you integrate with WCF and that WCF will integrate with Windows Azure. This doesn’t have anything to do with the book itself, the content is good. However is a book like this really needed? You have to judge that yourself. It is an engaging book that will introduce Windows Azure to Silverlight developers.

Mimic the Game Hub Application Bar with a Behavior on the BindableApplicationBar

A couple of days ago Sébastien Lachance wrote an excellent article about mimicking the application bar of the game hub. Really interesting for one of my applications which makes use of a minimal applicationbar that’s also transparant. However quite often the texts of the menu are difficult to read when they don’t have a solid backgroud. That’s exactly what is solved in the game hub: a transparant applicationbar, but when expanded to view the menu it has a solid background. And Sébastien also found a solution how to fix this in our own applications.

However Sébastien is using the ApplicationBar, I’m using the wrapper around the ApplicationBar, called BindableApplicationBar that’s part of the Phone7.Fx project. So how to solve this?

The ApplicationBar and BindableApplicationBar both implement the IApplicationBar interface which prescribes the StateChanged event that is used by Sébastien in his solution. So it looks like we can use the same event, let’s look a little bit closer…

Seems that the code inside the BindableApplicationBar never fires the StateChanged event, so let’s fix this with a little bit of code in the BindableApplicationBar. Please be aware that you need to use the source version of the BindableApplicationBar to be able to fix this. So let’s subscribe the underlying ApplicationBar first, we do this in t he constructor of the BindableApplicationBar by adding one line.

public BindableApplicationBar()
    _applicationBar = new Microsoft.Phone.Shell.ApplicationBar();
    _applicationBar.StateChanged += HandleStateChanged;
    Loaded += BindableApplicationBarLoaded;

Now we still need to implement the HandleStateChanged method, which is a pretty straight forward implementation you’ve probably seen thousands of times.

private void HandleStateChanged(object sender, ApplicationBarStateChangedEventArgs e)
    if (StateChanged != null)
        StateChanged(this, e);

So we now have a BindableApplicationBar that has all the features we need to mimic the ApplicationBar of the game hub. The rest of the implementation could be similar to Sébastien’s code. However I thought this is a typical thing that you can easily implement and reuse in a Behavior. I’m not writing behaviors daily, so I thought giving a look at the blog of the Behavior Master himself, Joost van Schaik. About a year ago he wrote a pattern for safe event detachment in behaviors.

So I started with this pattern as a basis. However my eagerness to make this Behavior perfect by immediately using this pattern caused me a lot of trouble. The pattern also tries to safely remove the events when the AssociatedObject aka Control is unloaded. The control I use is of a special type, the BindableApplicationBar, which immediately calls the unloaded event, don’t know why, but it took me almost an hour to find this out. In the end I did a step back and removed the Safe Pattern, and came to the following behavior. The essence is in the highlighted line where I set the BarOpacity property.

public class TransparantToFillApplicationBarBehavior : Behavior<BindableApplicationBar>
    private double? _originalBarOpacity;

    protected override void OnAttached()
        AssociatedObject.StateChanged += StateChanged;

    private void StateChanged(object sender, ApplicationBarStateChangedEventArgs e)
        if (!_originalBarOpacity.HasValue)
            _originalBarOpacity = AssociatedObject.BarOpacity;
        AssociatedObject.BarOpacity = e.IsMenuVisible ? 1 : _originalBarOpacity.Value;

    protected override void OnDetaching()
        AssociatedObject.StateChanged -= StateChanged;

And now you want to use it in your BindableApplicationBar, of course.

<ApplicationBar:BindableApplicationBar Mode="Minimized"
                                        IsVisible="{Binding LoggedIn}" BackgroundColor="{StaticResource PhoneBackgroundColor}">
        <ApplicationBar:TransparantToFillApplicationBarBehavior />
    <ApplicationBar:BindableApplicationBarMenuItem Text="about+settings"
                                                    Command="{Binding AboutCommand}" />

And the end result is like this. Transparent when the menu is collapsed.


And non-transparent when the menu is visible.