Skip to main content

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. […]

WPF MultiBinding

WPF MultiBinding

In WPF, it’s pretty common to display differenct properties of an object as if there where one. Typycally, I have a User, which contains a FirstName and a LastName and I want them both to be displayed as one. <TextBlock> <TextBlock.Text> <MultiBinding StringFormat=”{}{0} ({1})” > <Binding Path=”User.FirstName”></Binding> <Binding Path=”User.LastName”></Binding> </MultiBinding> </TextBlock.Text> </TextBlock> Enjoy!

How to connect to LocalDB in Visual Studio Server Explorer

Steps to connect LocalDB to Visual Studio Server Explorer Open command prompt Run SqlLocalDB.exe start v11.0 Run SqlLocalDB.exe info v11.0 Copy the Instance pipe name that starts with np:\… In Visual Studio select TOOLS > Connect to Database… For Server Name enter (localdb)\v11.0. If it didn’t work, use the Instance pipe name that you copied earlier. You can also use this to […]

Generate a PDF with Scryber

Today we will generate a PDF with the open source Scryber. The best way to work with Scryber is to use a template (PDFX file) for the style, the layout and the static content, then insert the dynamic content with C#. Full documentation at this link. Good example at this link. Create a new XML […]

Open a file with the default application

If you double click on a PDF file, it will be opened by the default application linked to that extension. So if Acrobad Reader is installed it will be opened with that application. In .Net, we have Process.Start which can start an executable. So if we start a PDF file, it will be openend by […]

StopWatch – measure your perf.

So let’s say you have a few operations to run and it takes a while to finish the execution. You would like to know which step is taking so long and how to improve the performance of the application. First, you could simply put a break point in each methods, but what if you want […]

Singleton

Multi threaded Singleton: using System; public sealed class Singleton { private static volatile Singleton instance; private static object syncRoot = new Object(); private Singleton() {} public static Singleton Instance { get { if (instance == null) { lock (syncRoot) { if (instance == null) instance = new Singleton(); } } return instance; } } }

Export DOCX to PDF

This is a simple code to convert any Word document to a PDF using the Word interop. using Word = Microsoft.Office.Interop.Word; … public Word.Document wordDocument { get; set; } public void ConvertWord2PDF() { var appWord = new Word.Application(); wordDocument = appWord.Documents.Open(@”D:\Tests\test.docx”); wordDocument.ExportAsFixedFormat(@”D:\Tests\test.pdf”, Word.WdExportFormat.wdExportFormatPDF); }  

Use a Dictionary

Here is a simple example of how to use a Dictionary with a Key-Value. var dico = new Dictionary<int, string>(); dico.Add(1, “Steeve”); dico.Add(2, “Morgan”); var result = dico.FirstOrDefault(x => x.Key == 1); var temp = result.Value; //temp = “Steeve”