Jul
11th | 2008

List.Sort(), Comparer and IComparable

Posted by Amit |
Filed under C# |

Hi

In my previous article I talked about why SortedList is not a good option to use if you need a sorted collection with keys that are not unique. Today I will show you how to use a regular generic List<T> to store sorted items. You basically have 2 options.

IComparable Interface

this means that you will have to make your stored class Implement the IComparable Interface. Here is an example:


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

How to Convert List(T1) to List(T2)

Posted by Shahar A |
Filed under .Net, C# |

Did you ever need to convert List(T1) to List(T2)? One example might be when implementing an interface. you might need to expose a collection of other interfaces (or maybe the same interface), But you usually hold the concrete type implementing the interface in the collection. Lets look at the following example:


Continue Reading...
Apr
23rd | 2008

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

4 Key Differences Between Implicit and Explicit Interface Implementation

Posted by Shahar Y |
Filed under C# |

Whenever we need to implement an interface in C#, two options pops up (click Ctrl+’.’):

Implicit vs explicit interface implementation, what shall be selected? before making a decision, lets understand what is the difference between those two.
Solving the diamond problem:
The diamond problem is related to object oriented languages that allow multiple inheritance. The problem raises when [...]


Continue Reading...

Search Dev102