Skip to main content

C# – DateTime.ToString() not displayed as I expected

Hello dear programmers, Imagine, you’re getting this nice string from this wonderfull object and BOOM: what you get is something completely different… I can see some unhappy faces here! This is the way to get the string as you expected. Did you know that actually writing the code DateTime.ToString(“dd/MM/yyyy”) or DateTime.ToString(“dd-MM-yyyy”), it’s just the same! It […]

C# – DST: DateTimeOffsets of the current day

Hey lovely programmers, Today I had a big frustration with an XML file I had to parse containing 25 hours for the 30/10/2016. All these hours where as String, and no way to use TimeSpan with 25 hours otherwise its the next day… The best way I found is to generate a list with all […]

C# – The Daylight Saving Time (DST) issue

Hey guys! The DST are a real pain in the ass for all developers. But I have got a little something for you! A DateTime extension method which will return the number of hours for the current Date. public static int GetNumberOfActualHours(this DateTime dateTime) { var hours = 24; var start = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, […]

C# – Kill any running application by code

This is a very simple way to kill an application by code under Windows. Don’t forget to add System.Diagnostics in the Using section. public void KillApp(string appName) { try { foreach (Process proc in Process.GetProcessesByName(appName)) proc.Kill(); } catch (Exception ex) { //TODO… } } Enjoy!

C# – Set the Wallpaper by code

There is no simple way to set the wallpaper. We have to use a Windows DLL to do that. And this DLL is able to set the wallpaper only if the image is a BMP. So we have to convert it first. using Microsoft.Win32; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Runtime.InteropServices; namespace WindowsStarter { […]

WPF – Missing Underscore with Label or CheckBox

Did you ever have a missing underscore with WPF?  If you have a Label or a Checkbox containing underscores, the first underscore will not be displayed on  screen. It is called the RecognizeAccessKey. Which allows you to reach the control with you keyboard by pressing ALT and the first lettre following the first underscore.  So […]

WPF – MVVM – Get filtered values from a GridView

The goal of this article is to show how to get the filtered items from a GridView (here we will use Telerik RadGridView, but it should be the same for any Grid). This case is really useful if you need to apply some calculation on a filtered subset of the Data you’re displaying, while you’re […]

WPF – Add a Watermark to a native WPF TextBox

This is how to add a Watermark to a native WPF TextBox without using a control from another toolkit.  The concept is to create a Style which will add a new property (called Tag) for your TextBoxes. The content of this Tag will be the watermark. And it will manage the events like if you […]

C# – Start any Windows application from code

To start any application by code, it pretty easy: static void Main(string[] args) { var pi = new ProcessStartInfo { FileName = “calc”, //Arguments = “…”, //RedirectStandardOutput = true, UseShellExecute = false //Allows the redirection of the ouput }; var p = Process.Start(pi); } But in that simple case, we could just do: static void […]

WPF – MVVM – Proxy Binding

Here the purpose is to be able to bind a Command on a Button which is under 2 levels of ItemsControl without using the “Ancestor” stuff. So the classic way of doing this: the following should work : <TextBlock Text=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Client.Name}” /> But we can do something better and more readable. […]