A WP7 databound graph control

For a project we are working on, we needed a simple (and free) WP7 graph usercontrol. The data which the usercontrol visualizes needs to be databound and each time new data arrives, the graph should update itself on-the-fly .In the following tutorial we’ll show how to create such a control from scratch (make note that normally this should also work in Silverlight or WPF projects).

A demo-solution of this tutorial can be downloaded here.

Read more of this post

Creating an Intellisense compatible enum-based Dependency Property

Actually, this post has a way too fancy title , because in fact I will merely show that enum-based dependency properties are IntelliSense compatible “out-of-the-box”. (by the way, if you know all about dependcy properties: simply read the line in bold and you’ll know all there is to know).

When creating a (WP7/SL/WPF) usercontrol, one often ends up creating one more dependency properties (DP). Most of the times you only want a discrete set of possible values that can be assigned to the DP. The logical choice then of course is to have an enum-based DP.

Now, for the Intellisense to work it is important that you define the enum type OUTSIDE the usercontrols class. For example, suppose we have define the following enum:

public enum GraphTypes {Default, Point, Line}

Now, all that remains is to add a DP that uses this enum (remember that you can use the ‘dependencyproperty’ snippet that comes with VS):

        public static readonly DependencyProperty GraphTypeProperty =
            DependencyProperty.Register("GraphType", typeof (GraphTypes), typeof (GraphControl), new PropertyMetadata(GraphTypes.Default));

        public GraphTypes GraphType
        {
            get { return (GraphTypes) GetValue(GraphTypeProperty); }
            set { SetValue(GraphTypeProperty, value); }
        }

Once you now add the usercontrol elsewhere in your xaml-code, IntelliSense will happily show what values can be assigned to the DP:

There we go. That’s all there was too it.

Next post I’ll show how to create a WP7 user control to plot graphs using data binding. Consider some of the code here a sneak preview.

Strokes: achievements while programming!

Ok, so I’ve already hinted about this several posts before: an actual implementation of achievements-based programming in Visual Studio is being made as we speak. In this post I will humbly and proudly present the Strokes program that is rapidly evolving into something I’m eager to use in my own classes. Humbly because the work Jonas Swiatek has done is, in my opinion nearly epic, for each component in the project that I understand, there’s about 3 others that I don’t. Proudly because, it being a googlecode project, I in fact have made several small contributions to the project, not in the least dozens of mails in which I describe my ultimate wishes on how the program should behave.

Explaining how the whole shebang works internally is not what this post will be about, instead, I’d like to simply throw around some pretty screenshots and show of the program the way the end-user might see it. Since this program was written to be as extendable as possible, in the end of this post I’ll give a brief overview on how others can use the Strokes-code to write new achievements.

Before reading on, I’d like to point out this project is still a work-in-progress. So if you are a) disappointed or b) excited, there’s 2 things you can do: you can help us out and contribute in any which way you see fit (provide ideas for challenges and achievements, contribute code or art, give basic feedback) or you can simply nod with your head sympathetically, leave and do other things *grin*.

If you want to see how it all works or make some contributions, all information can be found here: https://github.com/jonasswiatek/strokes. Make sure you read the wiki on how to setup your Visual Studio if you wish to test the current version of the project. And of course, don’t hesitate to contact us.

Update (24/08): An early beta can be downloaded of the strokes program so people can test the application themselves. Let us know what you think of it. Download here. Read more of this post

XML-databinding in WPF using Blend 4

This tutorial shows how easy it is to use XML-databinding in Blend without writing a single line of code and mostly using the drag-and-drop magic of Blend. We will create a very simple rss-reader that shows the content of a single rss-feed. This post was inspired by the great talk by Isabel Gomez Miragaya and Katrien De Graeve they gave at TechDays 2011 Belgium titled “Designing and Building a Windows Phone 7 Application end-to-end” (video of the talk). Read more of this post

Using Linq to filter a databound listbox in WPF/Silverlight

In this short tutorial I show how to use Linq in order to filter the items shown in a listbox, which in turn is databound to an ObservableCollection.

Suppose we use the listbox created in the previous tutorial where we show the age and name of each user in the collection. All our databinding code-remains the same as before. What we have to add is a new collection in between our original source and the listbox. The in between collection is our Linq-query result. Each time we wish to change our filter, we change the query. Read more of this post

Adding buttons to databound listbox items in WPF

Introduction

In this tutorial I will demonstrate how to create a listbox in WPF which is databound to a collection, we then would like to add a button to each item in the listbox. Clicking this button will button will delete that item from the collection.

Read more of this post

Follow

Get every new post delivered to your Inbox.

Join 329 other followers