The other day I needed to implement a search function in a WPF program. I wanted the use to be able to enter the criteria and then the enter key to perform the search. I achieved this by adding a KeyDown event to the text box control in the XAML. KeyDown=”textBox1_KeyDown” And adding the below […]
Read More →Author: Benjamin Perkins
Different return type from a method of a derived class

In .NET Framework 4, C# supports covariance and contravariance in generic interfaces and delegates. However, if you try to implement either in a class, you will receive an exception. Trying to implement covariance in a return type or overriding a method and attempting to return a different type will not work. Let’s discuss below. public […]
Read More →Generic Type Parameters parameter interface c#

I liked this concept because it seems kind of sneaky. By that I mean, in the past I was only able to call a method from a base class via inheritance or creating an instance of the class itself. However, now by implementing a generic type parameter we can achieve the same thing. First we […]
Read More →Generic Interface with a type constraint in C#
In a previous blog I discussed how to use and implement an interface with generics. I decided shortly after that it would be a good idea, in my context, to loosely bind a type to the interface. In the previous blog, it was left 100% generic and that was fine for the example. However, there […]
Read More →How to convert Dictionary keys or values to a List

I once had a requirement that I needed to dynamically build a select statement, based on a users selection and then display the results in a DataGrid. The tricky part was that the column name in the select portion of the query was not always the name I needed to show as the column heading […]
Read More →Simplified Deployment

DLL Hell. Enough said, well maybe not. Before .NET every installation of a new version of a program or the installation of any program was a gamble. There was always a risk that a necessary component required to run the new version would overwrite a component which is used by another causing the old program […]
Read More →Using Generics with Interfaces in C#
I wanted to create an interface; however one of the methods I wanted to implement in it had a class as a parameter. I thought about it and realized that be doing so I would be tightly binding my interface to a specific class. I didn’t think that was good practice because interfaces need to […]
Read More →Error – Class name is inaccessible due to its protection level

There is a pretty basic reason why this error happens. However, until you find the solution, it is a big deal. I was creating a simple base class like the below which I planned on extending in another class. public class TreeViewModel : INotifyPropertyChanged { TreeViewSelector() { } } However, when I tried to […]
Read More →Hey, the 90’s called and they want their website back

I got trolled once because of the way my website looked. I must admit, it did age a bit, but at the time I built it, using ADO.NET, ASP.NET Webforms (ASPX) and Master Pages, it was a pretty cool and sophisticated website for it’s time. Here is a tribute to my old C# blog look […]
Read More →Adding a context menu to a treeview Part 2

In my previous post I showed you how I added a context menu to a treeview. I had a new requirement that wanted a treeview property to contain a flag that could be turned on or off and that the value be displayed in the context menu. First I added the menuItem to the XAML. […]
Read More →