Skip to main content

Posts

DependencyObject in ViewModelBase - Good or Bad?

First of all, a very-very Happy New Year to all my readers. If you are reading this post, then I’m assuming that you have a working experience of WPF using MVVM.  Don’t worry, I’m not going to re-write a huge post on what MVVM is and where to use it? This blog is very small which talks about one of the best practices any developer implementing MVVM should follow. Well, let me provide you the context first. Last week I was going through one of my colleagues’ code and noticed few interesting things in his ViewModelBase class: It was holding few Dependency properties  It was inheriting  DependencyObject  How it sounds to you? Good or … ?  Of course, that is not at all a good practice as ViewModelBase is the base class for all the ViewModels and is not supposed to contain such code. Well, this is not the only reason.  There are many other reasons which are making this implementation a BIG NO.  1 st Reason – A DependencyObject was never meant to be a Source of a bi

Last blog post of 2016

This is my last blog of year 2016. I just want to take a minute to say thank you to all my readers who reads my blog. It’s prodigious erudition with you all. I wish you all a very Happy New Year and a great beginning. Catch you all in next year with same zeal :) 

AccessKey not working on WPF ContentPresenter

Recently I received a query from one of my friends stating that access key is not working in his WPF project when he is using ContentPresenter. So, I thought to share a post on it as it may be helpful for other reader also. Before digging directly into the problem, first let’s see what happens when access key is set directly on the Content property of a WPF Button. Below is my code for setting a Content on a Button: < Grid >         < Button Height ="39" Width ="100" Content ="_Save"/> </ Grid > If you will run your application with above snippet, you will notice that there is no underscore coming in front of word Save. But as soon as you press ALT key, underscore comes up. Which is an expected behavior :) Now tweak the code a bit and instead of setting content directly on a button, do it on ContentPresenter as shown below: < Grid >         < Button Width ="95" Height ="34" B

Can ASP.NET Core be chosen over ASP.NET MVC?

Nowadays one of the most popular question is ‘Can ASP.NET Core be chosen over ASP.NET MVC?’ So, to answer this question, let’s have a look at .NET architecture diagram:  By looking at above diagram, one can easily see that .NET framework is used develop desktop Windows applications using WPF and Windows Forms and Web applications using ASP.NET MVC. .NET Core supports UWP and ASP.NET Core libraries, in which UWP is used to create Windows 10 apps and ASP.NET Core is used to build Web applications for Windows/Linux/Mac operating systems. Now regarding what has to be chosen and when has to be chosen, I need not to re-invent the wheel because Jeff has written a very good article on it at ‘’Should I use ASP.NET Core or MVC5?’. Hope you find this post useful.

Live Unit Testing in Visual Studio 2017

Let’s have a look at one of the coolest feature of Visual studio 2017. If you will see below snapshot, there are many new icons here.  These icons are part of cool new feature called Live unit testing in Visual Studio 2017 Enterprise. Live Unit Testing continuously runs and displays unit test result and code coverage inside editor itself. It automatically finds and runs impacted tests for every line of code. In above diagram, Red cross indicates failed test case, Green tick indicates passed test case and Blue minus indicates the code that have no test coverage at all. Let’s start by looking at failing test case. You can quickly navigate to failing test case by clicking on tooltip as shown below:  And below is my test case: At this point, I’m not really sure why this is failing. So, I’ll go ahead and debug this test We can see here that above particular code has thrown a null referen

Performance and Memory tips

Two things play a very significant role in any application development, and those are application’s footprint and performance. Whenever I’m asked to work on these two tracks, I used to visit a huge list of sites to get many more ideas apart from what I already know. So, I thought, why can’t I collate all the good points and add them to my repository. At the same time, I thought of sharing those points in this blog. Rather than making this blog post full of theory, I’m planning to make it simple by just adding the bullet points. Uhh! Enough of gossip. Let’s get started by going through some common and important rules. Create object only when it is really required More the objects lesser the performance :(  Grab resources, use them and release at the earliest Default capacity of StringBuilder is 16. So, if you want to store less than 16 values then make sure to set the capacity. Avoid unnecessary boxing and unboxing Prefer lazy loading Use Static variables cautiously

Associating any file with an installed application

Recently I got a requirement to associate a file having custom extension with the installed version of our own application. So, whenever user clicks on that given extension file, it should open up directly in my WPF application along with the data population. So, let’s check out how you can achieve this: Step 1 - Creating an application: Create a WPF application or you can take any of your existing application. I’m working on WPF application (using MVVM) but the concept remains same for others, you can go with your Windows Forms or Console application also. That’s pretty acceptable. In my application, I'm taking few customer properties and a file path. Step 2 - Get key for Signing: For signing my assembly I’m using inbuilt feature of Visual Studio. Go to your project properties, navigate to Signing option as shown below:                                              If you already have a key then you can browse and associate it else you can always go ahead and