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.

Advertisements

7 WP7 dev tools you might not know but will want to have

There’s an incredible amount of guides, tools and utilities to be found on the Internet (or should I say ‘tha cloud’?) for Windows Phone 7 developers. Compiled in this article are some of the tools I’ve come across on my searches which I now use frequently but didn’t know the existence of beforehand. Read on to change you WP7 development life. Read more of this post

Strokes: new features have arrived

The Strokes project is still ongoing and several interesting new features have been added by my Danish friends! For those unfamiliar with this project (have you never read this blog???) , simply put: Strokes a Visual Studio 2010 extension that allows users to gain achievements while programming. It is mainly targeted to students who are learning C#; however some interest from the development community, especially VB.NET devs, also exists. Read this post for a full overview of the project.

The new features that have been added since my last post, in no particular order, are:

  • Achievement tree: It is now possible to define what achievement needs to be unlocked before the user can unlock a particular other achievement. For example, the user can’t unlock the “Create a foreach loop”, if he never ever unlocked the “create a for loop”. This allows us to prevent students from accidently unlocking things they never heard of before.
  • Localization: If anyone ever feels like using the Strokes extension in a particular language/culture, this can now simply be done as the achievement titles and descriptions can now be localized (currently supported languages are : English 100%, Danish 5%, Dutch 5%, Russian 0,01% )
  • More than 150 achievements and counting: Currently there are more than 150 achievements defined that the user can unlock. These are categorized in 13 categories. Yours truly is especially having fun in writing achievements in the Funny category (though your definition of what is in fact funny might differ a bit), especially the “What if Visual Studio had Achievements” post was a great inspiration.
Many achievments

Lots of new achievements and categories.

If you wish to contribute in any which way, don’t hesitate to contact us on our github page. Suppose you wish to write achievements, make fancy art, translate stuff, etc. join us and let eternal glory be yours!

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

“World of C#-craft”: an achievement-based classroom?

In a previous post I already briefly hinted at this: wouldn’t it be cool to integrate popular pc-game mechanics in classroom labs?


What I am proposing in this post is another way of organizing practical program labs for an audience that isn’t necessarily 100% willing to become a good programmer. Teaching C# classes to undergraduates electronics-ict isn’t always easy:

  • The crowd is pretty diverse: some have no programming knowledge at all, others have already written whole VB.NET apps, etc.
  • They aren’t all interested in the programming aspect of the studies but perhaps are more in to the electronics-part. However in the end, they will need to be proficient in both electronics and ICT.
  • They can’t see why toying around with console-based programs is, in my opinion, a necessary evil for first-time programmers.

However, in the end, all if these students have to become proficient programmers, whether they want to or not.

Having tried several approaches I don’t seem to be able to find an all-encompassing way to reach each and every last one of the students. I even tried to incorporate live voting and twitter integration in slides during lectures…an experiment with mixed results. Don’t get me wrong, I’m pretty sure I’m reaching above an average number of students, but still: I want all of them to love to program! I think I’d be a poorly ambitious teacher if my aim wasn’t to try and get a full classroom to become passionate about programming.

The idea that I propose here lingered for quiet sometime in the back of my head. Being a fanatic gamer myself I am always fascinated how simple game mechanics like achievements, quests, constant feedback of the player’s progress and leveling can make any ordinary game more fun and worthwhile to play. Somehow the act of earning things only a select few can reach is strangely addictive. So why not use these game mechanics in programming classes? Could a simple, yet fun and addictive achievement-system that constantly gives feedback to the student on his progress, enabling him to compare his results with others enable a teacher to reach more students? Could students become more motivated to do menial programming tasks (I dare anyone reading this to come up with fun programming tasks for the first few weeks, when the only thing a student knows is how to create variables and write stuff to the screen)? Of course, a small side note here: this system is primarily aimed for the gray zone of students who ‘might become passionate programmers’ but who usually, in classic classrooms, grow a mild hatred towards anything containing things like i++, public static overrive int, etc. Passionate students will enjoy this system as well, but they actually simply like to code, no matter the form they are learning new things…they might even think of this system as redundant.

This post is not about actually making an achievement-system that I propose. I’m merely trying to give the reader an idea of what I think might be an interesting way to organize a classroom and secondly I hope I can enable some people in actively pursuing this topic. I’m certain some of my ideas (that are far from original) can be as easily applied in any practical-oriented classroom in higher education systems.

So yes, this will be a braindump with, I hope, tiny little ideas that can grow in people’s mind. This won’t be a coherent, scientific rambling about how a classroom can be organized…I leave that to the educationists of the world. And perhaps, if I’m bored with the gazillion other programming ideas I have, I might someday write a follow-up where I actually show a real, useable application. Who knows. Read more of this post