There are a number of name differences between a windows form and a WPF program. For example, in a windows form program the event which is triggered when a user double-clicks on a data grid is called Doubleclick. The event in a WPF program is called MouseDoubleClick. Therefore the way to implement, program or add […]
Read More →Tags: C#
Get column value from DataGrid, NewItemPlaceholder, WPF, DataRowView and exception using C#
The way a problem is approached can have some serious consequences. Take for example the task I had to add some data to a DataGrid in WPF and allow a user to select the rows. When the rows were selected I would capture the details and put them into a form where they could be […]
Read More →How to add double quotes to a string
I needed to save an XML formatted file as a string which required double quotes around the attributes. The below code shows how to add double quotes to a string. string data = “<customer name=\”Ben Perkins\” class=\”Customer\”> <property name=\”Id\” /><property name=\”Address\” /> <property name=\”Occupation\” /> <property name=\”Remark\” /></ customer >”; Notice […]
Read More →No data in dynamically created DataTable visible in WPF DataGrid
It took me some time to find out that you cannot have periods “.” in the column name of dynamically created DataTables. I would run the query, created the columns and add the rows to the table, but nothing would show in the DataGrid when I bound it. I use the HQL interface from NHibernate […]
Read More →Add a Masked Textbox control to a WPF program
I found some very creative and technically challenging examples for adding a masked textbox control to a WPF program. Most of them required the creation of a new class inherited from the base System.Windows.Controls.TextBox class. This is a valid option, however, I have implemented a different approach. I discovered the System.Windows.Forms.Integration.WindowsFormsHost class which is specifically […]
Read More →Add images dynamically to WPF DataGrid using IValueConverter in C#
I created a WPF project which included a DataGrid which present a Status. It looked liked this. I didn’t really like the representation of the True, False, Null and decided to convert the value to either a Green, Yellow or Red image instead. To do this, I first added a class called BoolToImageConverter which implements […]
Read More →Access Localization Resources in WPF from the code-behind using C#
In a previous blog I discussed how to localize a WPF application. In that example we bound the localized resources in the XAML code. However, recently I needed to set the title of a MessageBox and I needed it to be localized. I added the below to my resource files. The name is the same […]
Read More →Setting the scrollbar for a treeview in WPF
I wanted a treeviews max height to be about 15% smaller than the window hosting it. This was because I wasn’t able to get (could not get) the vertical scrollbar for the treeview to show up without setting the MaxHeight property. Statically setting the MaxHeight property did make the vertical scrollbar show up, however when […]
Read More →NHibernate and Entity Framework essentials using a Model First approach
Object Relational Mapping technologies have been around for many years. Hibernate was one of the first, if not the first, ORM library which targeted the Java platform. Today, there are also NHibernate, which is a port of Hibernate to C# and the ADO.NET Entity Framework. Being a huge fan of the concept I am passionate […]
Read More →