Kategorie: Blog

Created with Sketch.

Creating a Generic Adapter with Empty Value in Android

In Android adapters are used sometimes to provide objects for a spinner. The following example shows how to extend that mechanism to add a null object. It was written using C# and Xamarin, but there should be no port to convert them to Java. Object base class: public class DatabaseObject { public DatabaseObject() { this.ID…
Weiterlesen

Prevent „Method not Allowed“ Error when using ASP.NET Web API

The error happens when the REST methods (POST, PUT, DELETE, etc). are already registered by another application. The following entries in the  web.config helped me to overcome the issue: <system.webServer> <validation validateIntegratedModeConfiguration=“false“ /> <modules runAllManagedModulesForAllRequests=“true“> <remove name=“WebDAVModule“ /> </modules> <handlers> <remove name=“WebDAV“ /> <remove name=“ExtensionlessUrlHandler-ISAPI-4.0_32bit“ /> <remove name=“ExtensionlessUrlHandler-ISAPI-4.0_64bit“ /> <remove name=“ExtensionlessUrlHandler-Integrated-4.0″ /> <add name=“ExtensionlessUrlHandler-ISAPI-4.0_32bit“ path=“*.“…
Weiterlesen

Using the jQuery DatePicker in ASP.NET MVC

This post explains in detail the steps necessary to use the jQuery DatePicker with the ASP.NET MVC Framework to enter dates, instead of the standard Textbox. The description covers globalization, localization, as well as validation. Required NuGet Packages In addition to the standard libraries of jQuery and jQuery UI, the following libraries need to be…
Weiterlesen

Convert .NET DateTime into Unix Time

The Unix calendar starts at 01/01/1970. This post will show you how to convert any DateTime value into a Unix time stamp. private const string InvalidUnixEpochErrorMessage = „Unix time starts January 1st, 1970“; /// <summary> /// Convert a long into a DateTime /// </summary> public static DateTime FromUnixTime(this Int64 self) { var ret = new…
Weiterlesen

Load Multiple Levels in Entity Framework using Linq.

When you use the Entity Framework to query data from a database, you often have to load detail data related to a database entry. Child elements can easily be obtained from the database with LINQ. Loading direct children: var steps = from b in db.Steps.Include(s => s.Questions) orderby b.StepOrder select b; By using the include…
Weiterlesen

Obtain IP and MAC Address in C#

There is no built-in way to discover the MAC address of your network adapter in .NET. Using the following function the MAC address that belongs to any IP address can be obtained. The functions use the external DLL iphlpapi.dll. public static class Network { [DllImport(„iphlpapi.dll“, ExactSpelling = true)] private static extern int SendARP(int DestIP, int…
Weiterlesen

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 { public static DateTime NextDate(this Random r, DateTime minDate, DateTime maxDate) { var ticks = maxDate.Ticks – minDate.Ticks; if (ticks > Int32.MaxValue)…
Weiterlesen

WPF Fix: Style is Only Applied to First Element

There is a bug in WPF that leads to a very strange behavior: A style that is defined in the resources is not applied to the first element, but to all others. This only happens when MergedDictionaries are cascaded. The following code is a valid XAML definition, but will not work as expected: <Application.Resources> <ResourceDictionary>…
Weiterlesen

Automatically grayed out Images in WPF

There is a new blog post about this topic with a new improved version of the AutoGrayableImage: https://www.engineeringsolutions.de/wp-admin/post.php?post=663 The following class is a WPF image control which is directly derived from Image. Therefore it can be used out-of-the-box like the standard WPF Image control. The image will automatically change to a gray scale image when…
Weiterlesen

Showing a ComboBox with Different Line Types

This can be used to choose the line type from a ComboBox, for example in a drawing application. The first entry is a solid line, the second is a dashed line and the last entry displays a dotted line. <ComboBox Width=“80″ SelectedIndex=“0″> <ComboBoxItem Height=“23″> <Line X1=“0″ X2=“60″ Y1=“11″ Y2=“11″ Stroke=“Black“ StrokeThickness=“2″ /> </ComboBoxItem> <ComboBoxItem Height=“23″>…
Weiterlesen