Development Tip – Dispatching calls to the UI thread

In Silverlight and WPF, if you wanted to update the UI from a thread you had launched, it was important that the UI update be executed on the UI thread, lest you get an invalid-cross-thread-access error. You could ensure this by initially getting a pointer to the dispatcher for the UI thread, and then asking…

1

Development Tip – Tab Control

I’m trying to replicate a tab control in the Windows 8 //BUILD release. I’m not talking about your traditional tab control with grey tabs and a static appearance; rather something that we’ve seen throughout the demos at //BUILD; a set of clean links at the top of the app that flip to different sections of…

6

Development Tip – Packaging and loading files

In Windows 8 I want to have a file in my solution which is packaged as part of the application, then read at runtime. It’s not immediately obvious how to do this because the app is running in an environment we’re not used to, and using StorageFile.GetFileFromPathAsync doesn’t let you provide relative paths. So what…

0

Development Tip – ObservableCollection doesn’t work

NOTE: This post applied in an the early preview of Win8. It’s no longer applicable because the bug in question no longer exists; ObservableCollection works just great 🙂 Original article below.     Just getting started with Win8 development, and will note what I learn in a series of posts.   I’m finding that ObservableCollection…

7

Useful C# method for unit testing

I’m unit testing a UI that needs to show some lists in various sorted orders, and I wanted to ensure that my tests would cover that. I found this method to come in handy:   1: public static bool IsOrderedBy<T>(this IEnumerable<T> coll, 2: Func<T, IComparable> val) 3: { 4: if (coll == null || coll.Count()…

3

Live Mesh Applications – whoah.

I’ve been playing with Live Mesh for a long time now, and have been loving it. During this time I’d been hearing about applications for Live Mesh, and while it sounded interesting in theory I didn’t really get what the point would be. Then I watched this video: http://briangorbett.com/mesh/mesh-video-player/   The video walks you through…

1

Be Paranoid. Be Very Paranoid.

Do you maintain an application with a backend database? Does that application ever write to the database? Be afraid. The worst situation to be in with respect to the above is when a customer mails you and says: “Why is my data gone?” 99% of the time, it’s because they clicked on the “Delete” button;…

2

Trivial but useful extension method

Don’t know why I didn’t write this before; it makes code very readable. Often when you write anything graphics related, you want to constrain coordinates to window edges (for example). So a simple method: 1: /// <summary> 2: /// Ensure that the given number falls within the 3: /// given min/max constraints. 4: /// </summary>…

3

On using Arrays

Eric Lippert has a great article on arrays: http://blogs.msdn.com/ericlippert/archive/2008/09/22/arrays-considered-somewhat-harmful.aspx   I think this is especially useful to consider if you’re writing an API. Consider not just arrays, but any time you’re returning any collection: Are you returning values or a variables? Did you mean to?   Avi

0

Code commenting? Try Business Commenting.

Jeff has a good post here about code comments and that they shouldn’t be used as crutches: Coding Horror: Coding Without Comments I agree with the article, but one thing I rarely hear mentioned is that it’s often more interesting to comment the business justification than it is to comment the code. Jeff goes some…

16