.NET 3.5 SP1

Creating a REST Client using WCF


Posted in:

A couple of weeks ago we received an email about consuming a REST service in WCF. Well, this tutorial should answer that email. Today we're going to build a simple client for Twitter's REST API using WCF.

Since it doesn't look like WCF natively support OAuth authentication, the client we're going to write will do one simple thing - request the latest status updates for a specific user. I'm going to write a command line application that asks for a username and then prints a bunch of status updates along with information about the user. Below is some example output.

Read More Icon Read More

WPF Tutorial - Binding Validation Rules


Posted in:

Bindings are a major part of WPF, and a big part of what makes it quick to create user interfaces in. They can be a little wordy and hard to debug sometimes, but overall they are extremely useful. Hopefully, after today's tutorial, you will find them even more useful - because today we are going to talk about building validation rules right into your bindings. Yup, you heard right - bindings in WPF have built in support for validation, and a number of the common controls have built in ways for displaying validation errors.

Read More Icon Read More

WPF Tutorial - Custom Control Templates


Posted in:

Almost every control in WPF uses a control template to define how it displays itself and its contents. In fact, you can override the control template on every built-in control to make it appear and act exactly like you want. Rather than overriding an existing template, however, this tutorial is going to demonstrate how to build a custom content control and use a control template to define how it looks.

Read More Icon Read More

Using the WPF Toolkit DataGrid


Posted in:

WPF comes with a large number of built in controls, but from the beginning it has lacked something that many application developers find extremely important - a DataGrid. You can use the ListView to create something approximating a DataGrid (I've talked about it in a couple different tutorials), but it is a lot of work and not particularly straightforward. Thankfully, Microsoft realizes how important a full-featured DataGrid is - and how you probably don't want to wait for the next version of WPF to be able to use one. This is where the WPF Toolkit comes in. The WPF Toolkit is "a collection of WPF features and components that are being made available outside of the normal .NET Framework ship cycle" which to me translates as "handy new controls I don't have to wait for".

Read More Icon Read More

WPF Snippet - Detecting Binding Errors


Posted in:

Isn't it really annoying when WPF binding errors fail silently? The application compiles, the application runs, but nothing is working - all because of a silly typo in a binding somewhere. And then, once you realize it is a binding error (which is not always obvious), you have to drudge through the debug output trying to find that one line that says "System.Windows.Data Error ....". Even worse than that is the subtle binding error where the app still works, but maybe the text on some label isn't updating right, and you don't even notice the bug until weeks later.

Read More Icon Read More

WPF Snippet - Determining If Text Is Ellipsed


Posted in:

So here's the problem - say you have a WPF TextBlock with some text (with automatic ellipsing turned on) and you want to know if the text is actually ellipsed at the moment. Sounds simple, right? Unfortunately, there are no properties or methods that you can call to check - well, no public properties or methods, that is. So this makes a simple question into a much harder answer.

Read More Icon Read More

WPF Snippet - Disabling Dragging from a TextBox


Posted in:

Reading the title, you are probably even wondering why this even deserves a tutorial. Disabling the ability to drag selected text out of a TextBox? That has got to just be a flag somewhere, right? That is what I thought, and it turns out I was quite wrong.

Read More Icon Read More

WPF Tutorial - Dynamic Data and the TreeView


Posted in:

One WPF control that we haven't taken a look at here on SOTC is the TreeView. Well, no more! Today we are going to rectify that, as we build an application that not only uses the TreeView, but also dynamically loads data into it on demand. We are going to cover a couple other new topics as well, including HierarchicalDataTemplates and CompositeCollections.

Read More Icon Read More

WPF Snippet - Class Event Handlers


Posted in:

Routed events in WPF let you do all sorts of crazy (and very handy) things. The fact that you can preview events on the way down the visual tree, as well as hook them as they bubble back up opens up a whole world of possibilities that would have been nothing but pain back in WinForms. But I'm not here today to wax poetic on routed events, I'm here to talk about some of the lesser known functionality of the WPF event system - namely Class Handlers.

Read More Icon Read More

WPF - Writing a Single Instance Application


Posted in:

Today we are going to be taking a look at how to build a single instance application in WPF. Not a single instance in this sense, but in the sense that you can only run one instance of the application at a time. Generally, you can run as many instances of an app at once (at least until you run out of resources). For instance, Notepad. You can run Notepad a dozen times, and you will get a dozen separate Notepad windows, and a dozen separate lines in "Task Manager" that read "notepad.exe". Killing one of those lines just kills one of those Notepad windows, and the rest live on happily.

Read More Icon Read More