C#

C# Snippet - Shuffling a Dictionary


Posted in:

Randomizing something can be a daunting task, especially with all the algorithms out there. However, sometimes you just need to shuffle things up, in a simple, yet effective manner. Today we are going to take a quick look at an easy and simple way to randomize a dictionary, which is most likely something that you may be using in a complex application.

Read More Icon Read More

WPF Tutorial - Increasing a Window's Border


Posted in:

Extending the window's frame is a design trend that is becoming popular in modern applications - especially browsers. Every major browser today (Chrome, Firefox, Internet Explorer, and Opera) uses this technique to increase the visual quality of their applications.

Today we're going to see how to duplicate this look in WPF. The approach we're going to take relies on the OS supporting Aero, which means only Vista and Windows 7 are supported. For Windows XP, you're going to have to find another solution.

Read More Icon Read More

WPF's Most Important Property - UseLayoutRounding


Posted in:

Ever since the introduction of WPF, applications developed using the technology have all had a similar look - fuzzy. In .NET 4, the developers at Microsoft made great strides in the clarity and readability of WPF applications.

Up until .NET 4, developers have used many tricks to get icons and line edges clearer than they are by default. Whereas some tricks may still be needed, one new property puts an end to much of the fuzziness frustration - UseLayoutRounding.

Read More Icon Read More

C# Tutorial - Optional and Named Arguments


Posted in:

When C# 4.0 was released, developers got their hands on some syntactic sugar that helps in the readability and maintainability of code - optional arguments and named arguments.

Read More Icon Read More

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

WPF Snippet Tutorial - Binding a DataTable to a DataGrid


Posted in:

This is something that I expected to be straightforward - binding a DataTable to a WPF DataGrid. The problem is that DataTable doesn't implement IEnumerable, and unfortunately that's what the DataGrid's ItemsSource property requires.

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

WPF Tutorial - Forcing a Binding Update


Posted in:

Here's a common scenario - you've got a WPF control bound to a property that doesn't update when the value of the property changes. If the object you have access to doesn't implement INotifyPropertyChanged or use Dependency Properties, this can be a very common problem.

Read More Icon Read More

Kinect Tutorial - Hacking 101


Posted in:

Microsoft's Kinect has been out for a few months now and has become a fairly popular accessory for the Xbox 360. Let's face it though, using the Kinect for what it was intended didn't end up being the most exciting part of this new toy. What has become far more interesting is seeing the various hacks developed that makes the device so much more than simply an input mechanism for games. Now it's your turn to do something amazing, and this tutorial will get you started. Today I'm going to get your Kinect up and running and demonstrate how to get the camera and depth information into your very own C# application.

Read More Icon Read More

How to Create .Net DataGridView Image Buttons


Posted in:

As you may have guessed by now, here at Switch On The Code, we are very big advocates of the .Net framework and all it has to offer. Sometimes however, things can be a little bit on the tricky side. Recently I ran into a tricky solution when I was trying to get image buttons in a DataGridView control, and in this tutorial I will go over the solution I came up with, which may just give you the edge the next time you need a fancy DataGridView.

Read More Icon Read More