Markiert: C#

0

How to Implement a DependencyPropertyWatcher

Dependency properties are widely used in WPF controls. However there is no buid-in way to listen to changes of such properties. The following class is a generic watcher for dependecy properties: public class DependencyPropertyWatcher<T>...

0

Extending the Random Class

The following code contains extension methods for the random class. One method will create random dates between a given minimum and maximum. The second method creates boolean random values. public static class RandomNumbers {...

0

Model-View-ViewModel (MVVM) Introduction

This post gives you an overview of the MVVM (Model-View-ViewModel) pattern. There are many similar very good articles like this, giving you a rough overview, historical background and/or nitty-gritty details on the pattern. Here...

0

Creating a WPF Spinner Control

In this post I will show how to create a spinning progress control in WPF. This is often used to notify the user that a long-running operation is still in progress, without without knowing...

0

Strip BOM from a File or Text

The following code removes the BOM (Byte Order Mark) from texts. Some text editors add that while saving files. Sometimes this leads to problems while reading or converting text files (e.g. XML files). The...

0

Check if Code is Executed at Design Time

Sometimes it is important to prevent certain code being executed at design time. public static bool IsDesignTime { get { return (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime); } } In WPF applications the following code can be...

0

Obtain information about the Executing Assembly

Path of the executing assembly: public static string GetExecutingAssemblyPath() { string codeBase = Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); return Path.GetDirectoryName(path); } Get title of executing assembly: /// <summary> ///...

0

Calendar tools and algorithms

Calculating a leap year The correct calculation of a leap year was first introduced by pope Gregor in 1582. The Gregorian Calendar is still commonly used in most parts of the world. Before that,...

0

Check Availability of a Server

This checks the availability of a server by sending a ping to the given IP address and waiting a certain amount of time for a response from the server: public static bool ServerAvailable(string ip,...