Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Wednesday, May 23, 2018

Visual studio tools / extensions and code snippets

Tools/extensions that I use with Visual Studio:
  1. ReSharper: For effective refactoring. Roslynator is a free alternative.
  2. Match Margin: "...highlights text in the editor for matches of the word under the caret". Note: This can also be done by highlighting the word and pressing ctrl+f
My code snippets can be found in Gist.

Monday, September 18, 2017

Using images as resources in C# WPF

To use images as embedded resouces in C# WPF (Visual Studio 2017):
  1. Go to Project properties / Resources tab.
  2. At the tab top menu, click the down arrow to the right of Add Resource and click Add Existing File.
  3. Select image files on disk. The files will be displayed on resouces tab. You will also notice that a Resources folder has been created in solution explorer.
  4. In solution explorer, select the image files under Resources and right click, select Properties
  5. Change Build Action to Resource
  6. In your code: MyImage.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/" + imgFileName)
  7. Clean Solution, Build Solution
  8. Now your code will run correctly. The image files will be embedded into the exe file, you won't need to distribute the images as separate files.