C#

C# Syntax Highlighting for HTML Pages

The following website can be used to generate html friendly representation of c# code

Tags:

C# Pass Arguments to the first instance of a program

Sometimes you don't want the user to run more than one instance of a program. But if the user associates a filetype with your programm it shall open the filetype in this first instance. The code below uses interprocess communication to find out if there is already another instance. It further allows the first instance to register an eventhandler which can be called from a second instance in order pass its command line parameters to the first instance.

This is how to use the code:

Tags:

C# Pitfalls

Closures

If you have code like this:

Tags:

Disable validation of Self-Signed Certificates

You can use the following code:

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

Be aware that this code does just accept every certificate and it is not only active for one request but for all requests. You should think before you use this code. But for development convenience or on a test system it might be ok to make your program easier to install and test.

Tags:

C# Entity Framework - Clear Context

Put the following code in the partial class of your entity context:

Tags:

WPF: Check if there are validation errors

I worked on a wpf window containing some controls that were required and that validated the format of the entered data. Once the user pressed a button I wanted to check if there was any validation error and notify the user with an error message. This is how to do it:

Helper class:

Tags:

C# Dijkstra

Implementation

Uses the HeapPriorityQueue.
Code on Github

Tags:

C# PriorityQueue with fast Update operation

Implementation

Uses a heap for fast retrieval of the smallest element as well as a dictionary for a fast access to an element which is already in the data strucutre. This priority queue is not too bad for implementing a Dijkstra (a fibonacci heap would be perfect...).
Code on Github

Tags:

C# PriorityQueue

Implementation

It is a simple implementation of a priority queue which is based on a SortedDictionary. This makes the implementation quite small.
Code on Github

Tags:

C# WPF Databinding

Databinding in General

If it doesn't work check:

  • You can just bind to a property. Check that you are not binding on a field

Databinding for ContextMenus in General

ContextMenus in WPF are somehow special. They exist outside the visual tree of the parent control and therefore they are unable to find for example the root element by name. In the following example the binding doesn't work:

Pages

Subscribe to RSS - C#