Hello Devz, It is common to have to export data to an Excel file. But sometimes the code have to run on a server where Excel is not or can’t be installed. And anyway, to be honest the Excel Interop is a real piece of crap to use… So Aspose did a good work by […]
C# – SI prefixes for metric units – because size matters
Sometimes you will have to play with numbers, BIG numbers… Or teeny-tiny ones! To avoid having too many zeros you can use the SI prefixes (like metric units: mm, cm, m, km, …). Here are the results of our code: 123,460000 -> 123,460 w (1000) 123,460000 -> 123,460 w (1024) 1.234,560000 -> 1,235 kw (1000) 1.234,560000 […]
WPF – PasswordBox Helper
Because security matters, you will need at one point to use a PasswordBox in your WPF application (you know, the textBox hiding the password with stars). But Microsoft didn’t make this control bindable for security reasons (in memory access). So if you’re using MVVM, it will be a bit tricky. Different solutions exist, but really […]
C# – Web Scraping – a simple HTML Agility Pack example
Hello Devz, Sometimes it can be useful to copy a part of the content from a website. That’s where web scraping is useful and HTML Agility Pack is one of the best tools to do it. In this tutorial, I will show you a simple HTML Agility Pack example. Decide what content you need Say […]
WPF – Inverted BooleanToVisibilityConverter
Hello Devz, WPF is providing a really useful converter called BooleanToVisibilityConverter. But the thing with this converter is that it’s really limited. Let’s say we want to use the same boolean to show one control and collapse another one, we just can’t… Here is new version of this converter that can accept a parameter to […]
C# – JSON serialize and deserialize
Hello Devz, JSON files are really common, we can see them everywhere. They provide a good structure to organize data, are simpler and lighter than XML files, and still human readable. In this simple example, we will show you how to use the Json.NET library (Newtonsoft) from NuGet. It is pretty simple to serialize and […]
C# – Copy a folder, its content and the sub-directories
Hello Devz, It’s unbelievable but yes, the System.IO provided by .NET doesn’t have a simple method to copy a folder, its content and the sub directories to another destination. There are a few different techniques to copy a directory with C#, using the command XCopy, or using a recursive method. The best one I saw […]
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, […]