In this article, we will talk about the config file used for a C# application. What is the goal of it, and how to use it. How to get values and create your own config section. What is a config file? It happens sometimes (quite often actually) that we need to store some parameters, default […]
WPF – Change color of a row in a DataGrid depending on the value with DataTrigger
Hi folks, Today we will see how to change the color or a row depending on the value of the content. To do that, create a simple View: <Window x:Class=”DataTrigger_Test.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″ xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″ mc:Ignorable=”d” Title=”MainWindow” Height=”350″ Width=”525″> <Grid> <DataGrid Margin=”10″ ItemsSource=”{Binding Users}” AutoGenerateColumns=”False” ColumnWidth=”*” HorizontalAlignment=”Stretch” VerticalAlignment=”Stretch” HorizontalContentAlignment=”Stretch” EnableRowVirtualization=”false” EnableColumnVirtualization=”false” CanUserAddRows=”False” CanUserReorderColumns=”False” CanUserResizeColumns=”True”> <DataGrid.CellStyle> <Style […]
Xamarin.Forms – Use built-in Dependency Injection (IoC)
Hello Devz, Xamarin.Forms have its own Dependency Injection implementation. Of course you can still use other ones like MvvmCross, Ninject and so on, but they will ask you a bit more configuration and changes in your code. The one from Xamarin.Forms works pretty well and is really simple to use. Here is a simple example. […]
WPF – DataGrid with single click checkbox
The problem with the checkbox in a WPF DataGrid By default, if you place a checkbox in a WPF DataGrid, you will have to click twice to check or uncheck the checkbox. And there is a logical explanation. The first click will select the row in the DataGrid, and the second one, the checkbox in […]
Add CodeLens to Visual Studio Community Edition 2015
Hey hardcore programmers, If you want to have CodeLens (yeah you know this little useful tool which gives you directly a link to where this code is referenced), all you need to do is install SSDT. And if you don’t need SSDT, you can just uninstall it afterwards, and CodeLens will remain. So first, download SQL […]
WPF – Override Decimal Separator for the current CultureInfo
Lets say we want to keep the current en-US culture format but override the way the Decimal is represented (normaly with a dot (.) but here we want a coma instead (,). System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(“en-US”); var currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture.Name; var ci = new CultureInfo(currentCulture) { NumberFormat = { NumberDecimalSeparator = “,” } }; System.Threading.Thread.CurrentThread.CurrentCulture = ci; […]
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!