Xml namespaces for custom control libraries

Ok, it has been a while since I posted now, but there has been a too much going on, and I guess I should be blogging about Silverlight 5, as it is on the agenda for MIX. I have even had the possibility to early access to the Silverlight 5 bits, but I have had too much to do to come up with some good posts about it. That is not to say that there isn’t a huge amount of really good stuff in the next release! But besides not having had time to play with it, I am not allowed to blog about it until it is actually available…

But, in the mean time, I thought I would do a quick post about a little feature that I am not seeing a lot of people using. It is nothing ground breaking, or even very necessary, but still helpful. I am talking about the ability to declare custom Xml namspaces to your assemblies…

More...

Code from my presentation at the NZALM conference

Earlier this week, I had the pleasure of presenting at the NZALM conference here in Wellington. Even though it was an ALM/Visual Studio conference, there was a “lot” of MVVM talk.

I did one intro session called “MVVM – The Naked Truth” and one deeper one called “MVVM – Going Beyond Hello World”. Both sessions went well according to me, but on the other hand I might be a bit biased… Hopefully the attending people would agree with me, but you never know.

As part of the talks, I did both write and show some pre-written code that I promised to put up here on my blog. So here it is:

MVVM - The Naked Truth.zip (18.88 kb)

MVVM - Going Beyond Hello World.zip (333.08 kb)

I also mentioned another blog post that would contain even more code samples. And since the search functionality on my blog for some reason is broken (I think it has to do with a new engine version with old theme…), I thought I would link to it from here instead. So here it is: https://chris.59north.com/post/SLAMD-session-code.aspx

If you have any questions about the code, just give me a yell or drop a comment and I will help out as much as I can!

WCF, Silverlight and T4…a good combination…

Ok, so this post is definitely going down in the books as “why would you do that” for a lot of people, but it actually has its benefits in some cases. What I want to show, is how we can work with WCF services and service interfaces without having to add a service reference to Visual Studio and instead auto generate the required code using T4 templates…

So why would I want to do that? Well, in some cases it is kind of tedious and even complicated to spin up the service just to be able to update the service reference and in some cases it isn’t even possible to get access to the WSDL that is required to create it. And in those cases, this will help you… In my case, the services and service contracts are built by one dev, and the Silverlight stuff by me. To us, this way of working makes it a lot easier to handle changes to the service contracts as we go along… I can get changes by just checking out the changed interfaces without having to try and get my solution into a state where I can update my service reference.

More...

Difference between Type.GetType() in Silverlight and .NET

I am currently working on a little thing in Silverlight and came across an interesting “feature”. The thing I am working on requires me to dynamically create types based on strings in a configuration file, and for this purpose, I created a simple TypeConverter called TypeTypeConverter. It is a very simple converter that takes a string and converts it to a Type. So I created a very simple implementation that looks like this

public class TypeTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if (value is string)
{
return Type.GetType((string)value, true);
}
return base.ConvertFrom(context, culture, value);
}
}

As you can see, it is probably a little TOO simple as it doesn’t handle errors at all. But to be honest, in my case it is actually a bit by design.

So why does this simple little thing end up on my blog? Well, because it failed… Not the code as such, but the thing I was trying to do…

More...

Introduction to setting up automated unit testing in Silverlight with NUnit

Ok, so MVVM is obviously about Unit testing right? Well, I don’t really agree, but it is definitely a part of why you chose MVVM, even if it is only a small part of the reason for me. I have been using the MVVM pattern for a while now, but I still haven’t started unit testing my code properly. I know I should, but for different reasons I never get around to it. Mostly due to time constraints.

And for all of you that tell me that writing unit tests will not take more time as there will be less bugs to fix, bug off! It does take time. It does include mocking or stubbing services. It does take time to figure out how to write useful tests. And first and foremost, it takes time to get the experience needed to do it fast… So argument ignored!

What I do do though though, is keeping it in my mind when I design my VMs. I always consider whether or no the VM is testable. If it is, then I know that I haven’t introduced any dependencies that I shouldn’t have. And even if it isn’t a fool proof way of limiting dependencies, it does help me…

More...

Multithreading my way

Ok, so Silverlight is a very cool technology, and Microsoft has done a whole lot of things to make sure that it performs the way it should. They have done things like forcing you to run long running tasks, such as webservice calls, in an asynchronous fashion. But if you start doing long running tasks on your own, you need to make sure to handle the multithreading yourself. Why? Well, if you don’t, you will perform all of that stuff on the UI thread.

And why is performing heavy things on the UI thread a bad thing? Well…it just is!

More...

Removing Design Time references at compile time

As you might have noticed on my blog, I like working with Silverlight, and I like using the MVVM pattern when I do so. As a part of this, I generally create design time ViewModels to get the best help from the tools (VS and Blend). VMs

The annoying thing about this, is that project containing the design time information need to be referenced by the application for the whole thing to work. But when the app is built and released, I really don’t want the extra ViewModels to be included in the xap file. I guess, in most cases, they are fairly simple and small, making the xap bloat minimal. But it still feels wrong. And it feels even worse when your design time VMs become large due to embedded resources such as images and data…

More...

Sessions for MIX11

Earlier today I got word that some of my sessions, that I had sent in as a part of the Open Call for MIX11, had gone past the initial round and are on the MIX11 website for voting. And the sessions that get the most votes gets to be presented at MIX11.

So this obviously means that I need a LOT of votes. And that means that I need you to vote on any of my sessions  that you find interesting. Or all of them if you just want to help me to get the possibility to present at MIX11…

The sessions are available here: http://live.visitmix.com/OpenCall/.

And what are my sessions? Well, I am glad you asked. They are…

Silverlight and Windows Azure - Tips from the Trenches
Join Chris Klug as he share his expertise in combining Windows Azure and Silverlight. This session will provide practical insights on using Silverlight with Windows Azure. It will include guidance on using Silverlight applications with Azure Web and Worker roles as well as approaches for using Windows Azure storage directly from your Silverlight app. This session will also cover the use of Windows Azure as a delivery mechanism for Windows Phone 7 push notifications and as a delivery mechanism for streaming media. Vote

From Phone Zero to Phone Hero in 60 minutes
Join Chris Klug & Chris Auld from Intergen as they build a real Windows Phone 7 app from scratch in 60 minutes. This is a hard core, dual data projector, coding marathon. Chris and Chris will build a Windows Phone 7 series application including Windows Azure hosted push notifications, a rich Silverlight UI and partner integration. You'll see how to take an idea from concept to the Windows Phone Marketplace in just an hour. In other words, not your general 'Hello World' application. Vote

MVVM - The Naked Truth
Model-View-ViewModel is the pattern of choice when writing Silverlight, WPF and Windows Phone 7 applications. It offers the developer a structured way to implement UI functionality and logic. It especially well with the mentioned technologies, as it uses built in features to enable a clean separation between form and function. During this session you will join Chris Klug, a Silverlight Solution Specialist from New Zealand, as he tells all about how you get started with MVVM. The goal is to get an understanding of why it is useful and how it can make your life simpler. And it will be presented in a naked form, no frameworks or helpers, enabling you to focus on the basic ins and outs of the pattern. Vote

Building Composite Silverlight Applications
Silverlight is a great platform for rich internet applications, but a lot of developers seem to forget that we can use many of our advanced desktop app approaches too. By adding a plug-in architecture we can make our apps easily extensible for future requirements. This session provides an introduction to plug-in approaches in Silverlight. It explores both PRISM and MEF as tools for implementing this pattern. You'll leave with the practical knowledge you need to add a plugin mechanism to your new and existing applications. Vote

The Phone Zero to Phone Hero will probably not be presented together with Christ Auld though as he probably won’t be able to go to MIX this year. But I will try and find a worthy replacement if that session were to get picked. And I really hope it is, cause it is a very entertaining session that is very far from your normal session. And also because it seems to polarize the crowd a lot. We have got feedback that ranges from more or less “the worst session ever attended” to “the best session ever attended”. Luckily, the good feedback seems to come from people who go to a lot of conferences and have a bit of experience, which is sort of required to grasp the information at the speed that it is presented…

That’s it for now. More coming soon… I hope… I have a little too much to do at the moment…

My view on HTML 5…and Silverlight

I continuously get questions regarding HTML5 and Silverlight. Especially after Microsoft’s somewhat brilliant comments at PDC. How is Silverlight going to survive now that HTML5 is coming? Why would you chose Silverlight over HTML5? Are you going to lose your job now that Silverlight is dying?

Well, I have finally decided to state my opinion  on my blog. It is obviously a biased opinion as I believe Silverlight to be a better choice in a lot of situations. So this is obviously a risky engagement, but I guess I will just have to endure the flaming I am going to get from a lot of people. Even a lot of people close to me.

But before I go too far, I do want to mention that we are living/working in an ever changing world. My opinions regarding the different technologies will probably change over time as the world changes. But this is my current view of the situation…

So…here we go…let the rant begin!

More...

MVVM and animation, revisited

A while back, quite a while back to be honest, I wrote a blog post about using animations in the MVVM pattern. And even if the way of doing it mentioned in the post still works, I would not recommend using it.

Adding the animation support in the way that that blog post says, will couple your VM to the StoryboardManager. Not that this really matters, as it will still be quite testable and so on. But it feels wrong…and I don’t like things that feel wrong…

In this post, I aim to cover a couple of ways that we can trigger animations and state changes based on the VM. And yes, these techniques have been hashed and rehashed on several other blogs, and you might already have read about it, but I still have people come to my blog to read the old post. So apparently it is still an issue for some…

More...