Experience the Windows Phone 7 Accelerometer using Wiimote

  image image

Let’s start at the beginning. What is an accelerometer? You can read about it in more detail here: http://en.wikipedia.org/wiki/Accelerometer, but effectively it’s a little doohickey that allows a device (in our case the Windows Phone) to detect the magnitude and direction of acceleration.

Windows Phone 7 (WP7) will have an accelerometer in it. The framework namespace that covers the accelerometer is Microsoft.Devices.Sensors. The class we care about here is the Accelerometer class. It has an important event called ReadingChanged. This event fires once you have started the accelerometer and one of the accelerometer values has changed. There are 3 important values, X, Y, and Z. Each represents the force of acceleration on that axis.

When I first started playing with the accelerometer I didn’t quite understand what the values for X, Y, and Z meant. When a device is sitting face up on a desk, X and Y will both be zero (or close to it). Z will be 1. Keep in mind that these values can be greater than zero for when greater than normal forces are put on them. Shaking for example.

As you can probably figure out, based on these values you can tell when a user tilts to the left, right, top, bottom, up or down.

Unfortunately there’s no easy way to test accelerometer code using the WP7 emulator. The one I like the most is using a Wiimote’s accelerometer. This was Bill Reis‘s idea.

For more goto Introduction to the Windows Phone 7 Accelerometer

Using The Silverlight DataGrid with MVVM

 image

View Model and the Silverlight DataGrid

The Silverlight DataGrid is a powerful control that allows inline editing, paging, sorting, and drag and drop re-ordering of columns. It can be challenging to understand when using normal code behind techniques, but sometimes downright baffling when using View Model / MVVM style programming.

In the following examples, we will not directly reference the DataGrid in the View Model. The code we will create can be consumed by any collection control such as a ListBox.

It’s Not The DataGrid You Want to Manipulate – It’s the Collection Bound To The DataGrid

For more -> Using The Silverlight DataGrid with View Model / MVVM – CodeProject

In conclusion – View Model – Less Code, Really!

Hopefully you can see that View Model is not hard at all. It really is not complicated once you see how it is done. Expression Blend was designed to work in "View Model Style", so you should have an easier time using Expression Blend when you use this simple pattern.

While it may seem easier to implement a DataGrid using code behind, you will usually find that you will need to create a lot of code to locate and modify values and properties in the DataGrid.

Controls such as the DataGrid are designed to Bind to collections. View Model is designed to implement binding. It’s the Binding that saves you code. Once a Binding is created, it will perform functionality automatically. you do not have to explicitly write code for each piece of functionality. Most importantly, you will Bind to, and gather parameters, directly from the DataGrid element that you are ultimately concerned with, rather than hooking into an event and then hunting for the real value you are looking for.

Furthermore, you will realize that a lot of programmatic functionality, is best implemented, on the underlying data source not the DataGrid it’s self.

Also note, this example uses standard web services, you can easily use WCF or WCF RIA Services. The View and the View Model would still be exactly the same.

Asynchronous Cancellation Patterns with .NET 4

 image

For calling methods asynchronously, since .NET 1.0 the async pattern can be used. .NET 2.0 added the event-based async pattern (also known as async component pattern) that makes async calls easier with Windows applications. Before .NET 4 no standard mechanism has been available to cancel asynchronous method calls. That’s new with .NET 4.0.

In this blog series you can read about these async patterns as well as the new unified model for cancellation.

Part 1 of this series introduced the async patterns and introduced cancellation with the BackgroundWorker class as it existed since .NET 2. In part 2 of this series Christian will show how the new .NET 4 cancellation framework can be used.

Previously to .NET 4, cancellation with async method calls was implemented in different ways if it was supported at all. For example, the BackgroundWorker implements cooperative cancellation by invoking the CancelAsync method, the long-running method needs to verify if it should be canceled by checking the CancellationPending property and needs to cancel by setting the Cancel property of the DoWorkEventArgs. More about this in the previous blog entry.

.NET 4 now supports cooperative cancellation of async methods in a standard way. The heart of this new framework is the CancellationToken struct. The CancellationToken is created by a CancellationTokenSource. This token can then be passed to any activity that should be cancelled. In case of a cancellation, the async call can verify cancellation by checking the IsCancellationRequested property of the CancellationToken. This unified model is now available with several classes offering asynchronous requests.

Templating ListBox Controls with Silverlight

image 

http://channel9.msdn.com/shows/SilverlightTV/Templating-Controls-with-Silverlight-Silverlight-TV-36/

This video demonstrates the power of templating using a ListBox and its various templates, including the ItemsPanel, ListBoxItem, Data Template, and more. This is a great episode to watch if you ever wanted to know how to template controls, or even if you just want to know what all those templates are for and how to use them in Blend.

Using Behaviors in Blend

image  image

Adam Kinney demonstrates how to take advantage of behaviors in Expression Blend 4. He creates several demonstrations using the new DataStore and conditional behavior features in concert with several new behaviors including ChangePropertyAction, ControlStoryBoardAction, SetDataStoreValueAction, and the custom Mouse3DBehavior.

Via Using Behaviors in Blend 4 (Silverlight TV 30) | Silverlight TV | Channel 9

Microsoft Design .toolbox – Learn to create Silverlight application using Expression Studio

image

scenarios

Learn the fundamentals of Silverlight and Expression Studio. Start with basic techniques and build your skills to create more advanced applications. Design Scenarios is comprised of four levels that increase in difficulty with three training modules per level. Each module deconstructs a Silverlight application to teach you must-know features and techniques

principles

All great applications start with a foundation in design. The Design Principles track gets back to basics with key design concepts that will help you create slick and functional web applications. Each of the four level groupings contains three modules, each focused on design fundamentals.

 

Visit http://www.microsoft.com/design/toolbox/