.NET

WPF DataGrid Tutorial - Row Headers


Posted in:

When using Data Grids to present data, row headers can be valuable additions - especially if the grid contains more columns than can fit on the screen at one time. Row headers don't scroll horizontally with the rest of the content, which means users can use them to see the context of the data they're viewing. This tutorial will demonstrate how to create row headers using WPF's DataGrid control.

Read More Icon Read More

C# Tutorial - Triple DES Encryption


Posted in:

The Data Encryption Standard (DES) has been around since the 70's, enjoyed wide-spread adoption, and has since been retired due to its small key length and ease of brute-force attacks. Triple DES, which is basically the same approach times three, aimed to remove the practicality of attacks while keeping the same basic algorithm. Although it's slowly being replaced by AES, triple DES is still a viable approach for your basic encryption needs.

Read More Icon Read More

C# Code Generation


Posted in:

Code generation is a big part of most modern frameworks. .NET is full of code generators that you've probably used - maybe without even knowing it. XAML files are converted to .g.cs files that are then fed to the compiler at compilation time. WCF is bundled with a code generator that will convert a WSDL file to a client to easily connect to existing web services. Today's tutorial will cover how to use objects provided by the .NET framework to build your own code generator.

Read More Icon Read More

C# Tutorial - Using the BackgroundWorker Class


Posted in:

It's a rule that should never be forgotten - don't ever perform work that takes a non-trivial amount of time on the UI thread. Of course you're now wondering, "Where do I perform tasks that take a non-trivial amount of time?". The answer is simple - on a different thread. There are lots of ways to get your work onto another thread, which can include directly creating a Thread or using the ThreadPool.

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

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

Creating and Reading Global Attributes in C#


Posted in:

Global attributes aren't something that many C# developers use often, however almost every application contains them, whether you're aware of them or not. Global attributes are a great way to store meta information for a specific assembly or module.

Global attributes are split into two categories: assembly and module. A module is a single code file and an assembly is a single DLL or executable. An assembly can contain several modules and a module can contain several classes.

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

Creating MSBuild Tasks in C#


Posted in:

At some point with any decently complex project, you are going to need to start customizing your build process. Visual Studio makes this possible, and not too terribly painful, by giving developers the ability to write custom MSBuild project files. But eventually, you are going to hit the limit of what the MSBuild XML syntax can do for you - but when you reach that point, there is something else waiting - custom tasks! MSBuild gives you the ability to write custom build tasks in C# (or any .NET language), and use those tasks inside of MSBuild project files. We are going to be taking a look today at how to create these tasks and how to use them.

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