May
14th

How To Add a MouseDoubleClick Event To Any WPF Control

Posted by Amit |
Filed under .Net, WPF |

Last week I was faced with a problem. I needed to implement a MouseDoubleClick Event on a WPF Grid. I said Ha, easy but as i went on to implement it i realized that the Grid has no MouseDoubleClick Event! So how am I supposed to implement it? I came up with 2 solutions and so here goes:

  1. the first thought i had was to create a User Control that held only a grid and implement the MouseDoubleClick on the User Control itself so what you will get is this Xaml code:
  2. <UserControl x:Class=”CustomDoubleClick.GridWrapper”
        xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
        xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
        Height=”300″ Width=”300″>
        <Grid>
    
        </Grid>
    </UserControl>
    Since the Grid takes the…

    Continue Reading...
Apr
23rd

WPF DataTemplate for Interfaces? Not Supported

Posted by Shahar Y |
Filed under .Net, WPF |

DataTemplates are a great feature introduced in WPF, it allows to determine how data is presented and how data binding accesses the presented data. Just as we can apply a visual style to a specific UI control, we can do it for a specific data type. There is just one problem here, DataTemplates are good [...]


Continue Reading...
Apr
21st

A Bug in WPF Static Resources?

Posted by Amit |
Filed under C#, WPF |

Yesterday I played around with WPF resources and stumbled on a very strange behavior. It seems that the order of the elements in the resources have some importance as to how the application handles them. A few code examples are attached


Continue Reading...
Apr
15th

How to Create a Word Like Font Selection in WPF ComboBox

Posted by Amit |
Filed under C#, WPF |

If you are writing an application that uses font you will find this post very useful. Making a font selecting ComboBox that shows a preview of the fonts in WPF is very easy, here is how to do it:
First we will have to create the ComboBox Code, this is a regular ComboBox we have all [...]


Continue Reading...
Apr
3rd

Is WPF Data Binding thread safe?

Posted by Shahar A |
Filed under WPF |

We wanted to check whether WPF data binding is thread safe, and made a little test (using .NET 3.5). Lets look at the Worker class, which has one property - Money, and is making money in a multithreaded way :) - creating 100 threads and increasing the “Money” property from each one of them:
class Worker : INotifyPropertyChanged [...]


Continue Reading...
Mar
25th

Customize SpellCheck on WPF Text Controls

Posted by Shahar Y |
Filed under WPF |

WPF has a great feature for spell checking called SpellCheck, which is applied on TextBox and RichTextBox controls. In this post I will explain about it and how can it be customized. Lets go back to the start, to activate the spell checker just set SpellCheck.IsEnabled property to True. Easy, right?. Take a look at [...]


Continue Reading...
Mar
24th

Using WinForms with WPF, Watch Out!

Posted by Amit |
Filed under C#, WPF |

Here is an interesting thing that happened to me at work.
For various reasons the application i am working on has a Windows Form in its base, and most of the controls are WPF, part of them are WinForms. The weirdest thing happened to me as i was trying to open a WPF Window from one [...]


Continue Reading...
Mar
10th

How to Sort Elements in a Content Control Without Touching The Data.

Posted by Amit |
Filed under C#, WPF |

Often we want to display a list of elements and allow the user to sort them in various ways. There are many ways to do it and I wanted to show you how to use a SortDescription Object. What is a SortDescription object you ask? It receives two parameters in its constructor: the first is [...]


Continue Reading...
Mar
7th

Binding a WPF Control To a Dictionary

Posted by Amit |
Filed under .Net, C#, WPF |

Binding to a dictionary can be tricky.
It sounds simple but it never works on the first try. Usually when you first run you application you see that instead of the beautiful template you created for the items, you get something that looks like a pair of key and value. your binding works fine, you just [...]


Continue Reading...
Jan
14th

How to Solve error CS0103: The name ‘InitializeComponent’ does not exist in the current context

Posted by Amit |
Filed under C#, Visual Studio, WPF |

Hi.
Ever had the following error in Visual Studio:error CS0103: The name ‘InitializeComponent’ does not exist in the current context.I sure did…
There’s a very specific reason for this and it’s in the project settingsThis usually happens whenever you try to add a WPF control/window to a .NET 2.0 Class library or project. The reason for this [...]


Continue Reading...