Introduction This post is about the Options Pattern in ASP.NET Core and how to use it to retrieve values from the AppSettings.json file. I will also explain how to inject the options into your classes and provides an example of using the Options Pattern in unit tests. What is the Options Pattern? The Options Pattern […]
C# – Parse String Hour to TimeSpan or DateTime
Converting a String to something else can always be tricky. Especially if that String is about time. The thing is the fact that there are many ways to represent time and that can actually depend on the country you are. 6 PM, 6.00 PM, 06.00, 06:00, 18:00, 18h00, 18H00, they could be all the same. […]
WPF – OpenFileDialog
This is a simple example to have an OpenFileDialog (a premade view done by Windows to select a file to open) with WPF, filtering on XLSX file: In this case the InitialDirectory will always exist because it is the Desktop of the current user. But you have to know that if the targeted InitialDirectory doesn’t […]
C# – Read Settings from the AppSettings.json
You might be used to the good old web.config or app.config file. But if you upgrade your solution to something a bit more modern like .Net 5, then it will be transformed to appsettings.json. Here are some tips about how to use the appsettings.json. The app.config file was stored as an XML file. So you […]
C# – Upgrade Your Solution To .Net
This article will talk about how you can easily upgrade your .Net Framework solution to .Net 5 (6, Core, Standard). Microsoft released a simple dotnet script to do this painful task for you. Currently the tool supports the following .NET Framework app types: .NET Framework Windows Forms apps .NET Framework WPF apps .NET Framework ASP.NET […]
WPF – Animated Image
It is sometimes interesting to have an animated icon to tell to our user that their command is actually processing. Typically for a refresh icon. So, two solution: you could use an animated GIF and use an external library like WpfAnimatedGif (or the XAML MediaElement), or use an rounded icon (like this one) and create […]
WPF – Animated text
Sometimes it can be useful to have an animated text even in WPF. Typically a “Loading…”, where the 3 dots are moving one by one. Here is a simple way to do an animation with text: <StackPanel Orientation=”Horizontal” Margin=”20″> <Button Content=”Start” Height=”20″ Command=”{Binding StartCommand}” VerticalAlignment=”Top” Margin=”5″ /> <Button Content=”Stop” Height=”20″ Command=”{Binding StopCommand}” VerticalAlignment=”Top” Margin=”5″ /> […]
WPF – Nullable binding
Hello Devz, Imagine you have a TextBox binded to a nullable integer and you put a value in it. Now let’s say you delete this value. You expect to have your value to be null. To be able to do that, you need to update the properties of you binding like this: <TextBox Text=”{Binding Value, […]
C# – Simple email validation regex
Hello Devz, Do you have a web or WPF application that needs email address validation? Regex (regular expression) can help you. This post outlines a simple email validation regex that you can use straight away. What is a regex? A regular expression (regex for short) describes a search pattern using a particular text string. It’s […]