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