Jul
17th | 2008

WPF Binding Converter Best Practices

Posted by Amit |
Filed under WPF |

Hi all

As you all remember in my article about Custom WPF Context Menu I mentioned that my WPF Binding Converter was a singleton, and I promised to tell you why, so here comes the 3 ways I know of using WPF Binding Converters. We will start from the worst (in my opinion) and move on the the best.

To start off here is the Binding Converter:


Continue Reading...
Jun
20th | 2008

How To Create a WPF Custom Context Menu

Posted by Amit |
Filed under .Net, WPF |

How would you like your WPF application to have a Context Menu like this:

Context Menu Example

Well, It is not so hard. Here is how you do it:


Continue Reading...
Jun
18th | 2008

Diagnose Assembly Binding Failures

Posted by Shahar Y |
Filed under .Net, Misc., Utilities, Visual Studio |

Every one of us, software developers, experienced situations where the .Net Framework could not locate an assembly and ended up facing the TypeLoadException. These failures usually happen due to an assembly deployed to the wrong location or a mismatch in version numbers or cultures. A quick way to check what went wrong is to open the module window (Visual Studio) during debugging but that may be sometimes impossible or inconvenient because:

  • We may not have Visual Studio installed. 
  • We installed the product in the customer site and we don’t have the code available.
  • It is some third party assemblies which causes the problems.

Luckily, there is an assembly binding log viewer which displays information that helps us diagnose why the .NET Framework can not locate an assembly at run time. This tool is called


Continue Reading...
Jun
13th | 2008

Why Should You Use The x:key Attribute In WPF DataTemplates

Posted by Amit |
Filed under .Net, WPF |

We have all used WPF DataTemplates, but I bet most of you never gave thought to the meaning of the x:Key attribute. We all know the meaning of the DataType attribute, which determines to what type of data the template will apply to. But what about the x:Key why is it there? Lets tale a look at the following code:

<Window.Resources>
        <DataTemplate DataType=”{x:Type data:s}”>
            <Button Width=”50″ Height=”50″>
                <TextBlock Text=”{Binding text}”></TextBlock>
            </Button>
        </DataTemplate>
    </Window.Resources>
    <Canvas>
        <ItemsControl ItemsSource=”{Binding}”>
        </ItemsControl>
    </Canvas>


Continue Reading...
May
27th | 2008

How to Create a WPF Two Level Master-Detail Application With ComboBoxes

Posted by Shahar A |
Filed under C#, WPF |

Master-Detail is a pattern for displaying details of a specific item selected from a list of items. In this post I’ll demonstrate how to use master-detail in WPF with two levels of objects, each displayed in a ComboBox and Data Binding to tie them together.


Continue Reading...
Apr
21st | 2008

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 | 2008

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...
Mar
10th | 2008

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 | 2008

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...

Search Dev102