MVVM your Kinect code
- Posted: Aug 16, 2011 at 6:00 AM
- 7,363 Views
MVVM is a pattern that I'm a fan of. It's a solid step toward developing application UI's that are easier to maintain and test by removing, eliminating the need for, "code behind" code. If you've ever had to maintain any app of any complexity over a period of time that relied on code behind, you'll know what I mean when I say that a real, reliable and "standard" replacement pattern is very welcome.
Now lets mix in Kinect and MVVM and let's see what we get...
Now that the official Kinect SDK is out I've been looking for good patterns when incorporating it into Windows 7 applications. The Model-View-ViewModel (e.g. MVVM) pattern is my pattern of choice for WPF applications and I wanted to demonstrate how I incorporate the Kinect runtime within the MVVM pattern.
I've created a screencast walk-through of how you can incorporate the Kinect runtime into MVVM (or read on below for a brief description of the approach).
Project Information URL: http://kindohm.com/2011/07/20/KinectMvvm.html
Project Source URL: https://github.com/kindohm/kinect-mvvm
public class ViewModelLoader
{
static ViewModel viewModelStatic;
static IKinectService kinectService;
public ViewModelLoader()
{
kinectService = new ConcreteKinectService();
var isInDesignMode = ...; // detect if running in VS designer
if (!isInDesignMode) kinectService.Initialize();
}
public static ViewModel ViewModelStatic
{
get
{
if (viewModelStatic == null)
{
viewModelStatic =
new ViewModel(kinectService);
}
return viewModelStatic;
}
}
public ViewModel ViewModel
{
get
{
return ViewModelStatic;
}
}
public static void Cleanup()
{
if (viewModelStatic != null)
{
viewModelStatic.Cleanup();
}
kinectService.Cleanup();
}
}
Contact Information:
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?