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...
May
13th

Beware of List.Find()

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

List<T>.Find() returns the first element found that matches a given criteria. So lets say we have List<int> and we use the Find method on it. What will be the returned value? If a number in the list matches the criteria it will be returned, but what if not? what does the variable zero contains after executing this code:

List<int> listOfInts = new List<int>(new int[] { 1,2,3,4,5,6,7,8,9});
int zero = listOfInts.Find(
    delegate(int i)
    {
        return i == 0;
    });

It has the value of…


Continue Reading...
May
1st

Operator~ and BinarySearch

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

Usually, we use Array.BinarySearch to find a value in a sorted array, we all know that this method returns the index of the searched value in the array, if value is found. It turns out that the return value of BinarySearch is much more interesting and useful. Lets focus on what happens if the value is not found in the array.

Those who claim that if value is not found than a negative number will be returned, are absolutely right. But most of us don’t really know the whole truth about that negative number and how it can be used.

magnifying-glass


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
18th

Don’t Use Double.Nan

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

Comparison of a double with double.Nan (Not a Number) will always return false. Even (double.Nan == double.Nan) return false and indeed, from IEEE 754 specs: equality comparison between two Nan is always false. If we want to check whether a specific double is Nan, double.IsNan() shall be used. Lets look at how the IsNan [...]


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
14th

Unhandled Exceptions - Handle them

Posted by Shahar Y |
Filed under .Net, C#, Unmanaged Code |

It is common knowledge that there is no such thing as software without bugs. There are several bugs out there that are hiding and therefore are not handled at all. We surely don’t want to release a software that will crash ungracefully due to such a case. Fortunately, the .Net framework makes it possible to [...]


Continue Reading...
Apr
11th

Free Tool - Extract Hard Coded Strings to Resource Files

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

Recently, I ran into a great free Microsoft tool which is called - Resource Refactoring Tool. This tool provides developers an easy way to extract hard coded strings from the code to resource files.
Resource files (.resx files) consists of XML entries, which specify objects and string inside XML tags. Those files can be opened with [...]


Continue Reading...
Apr
9th

Is It Possible? .NET Applications for iPhone?

Posted by Amit |
Filed under .Net |

According to this site It seems that Yes!
The Linux Project Mono was recently converted to the iPhone platform. Pay close attention that this is only the start but it seem that the day when we will see .NET applications running on iPhones is not far away… The question is will the iPhone still be around [...]


Continue Reading...
Apr
8th

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