Every one knows that when different threads write to the same data structure they need to be synced.

Lets assume we have a Service that exposed a single function Add which added the value received to a List.

   1: public class ListWrapper

   2: {

   3:     private readonly List<int> m_list =new List<int>();


   5:     public void Add(int i)

   6:     {

   7:         m_list.Add(i);

   8:     }

   9: }

In order to make it thread safe we would simply lock the List so if multiple thread try to access this function they will add their values to the list each at a time.

   1: public void Add(int i)

   2: {

   3:     lock (m_list)

   4:     {

   5:         m_list.Add(i);

   6:     }

   7: }

For 99.9% of the applications this is a good solution.

Continue Reading...




I you worked with the WebBrowser control you probably met the following popup:


script error


I have started to use the WPF WebBrowser control in some of my applications but when I tried to disable the script errors I had a small problem the property WebBrowser.ScriptErrorsSuppressed  was not there, bummer…


Continue Reading...

Last week, I stumbled upon the following piece of code:


IList<double> doubles = new List<double> {22.123, 400.12, 100.22};
foreach (int number in doubles)
    Console.WriteLine("The Current Number Is : {0}", number);

Can you see the bug in that code? We convert all of the doubles in the list to integers, truncating them. I was very surprised that the compiler didn’t warn me about this issue, especially because the compiler would not let me write this code:


Continue Reading...

Suppose you have several objects in your WPF application filled with similar Brushes which differ in brightness only. Like in this image:



The nine rectangles use the same RadialGradienBrush but each rectangle is a little darker than previous. You can create these 9 different brushes in your favorite design tool (Expression Blend, etc.). But what if you need to change the base color later or you just need to make the brush user-configurable? Like in these samples:

Continue Reading...



When working with WPF I always found myself thinking how to handle Data formatting when a WPF control was bound to it. Let’s look at the following example of a window with a TextBlock that displays a DateTime:

   1: <Window x:Class="BindingFormat.Window1"

   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

   4:     Title="Window1" Height="300" Width="300">

   5:     <Grid>

   6:         <TextBlock Text="{Binding}"></TextBlock>

   7:     </Grid>

   8: </Window>

Continue Reading...

This article was written by Alan Mendelevich

The Problem

Creating a shape with bullets on the joints of it’s segments sounds like a really trivial task at a first glance. Just plaster some bullets on top of the shape. And it is really something like this until you decide you want to have transparent outlined bullets or opaque bullets with transparent outline around them. Like the ones in this picture:



Continue Reading...

Let me share you with one of the weirdest errors I ever encountered. Recently, I have been working on a distributed application which is built from a server and some clients. The clients are Windows Forms applications. Yesterday, I spent a whole day chasing a very weird and strange error – I was getting an exception at the main method (unhandled exception) of the client application. Here is what I got:


The error description was:

Continue Reading...

This article was written by Alan Mendelevich




Recently I’ve been working on a set of custom WPF controls.

There are numerous good books and articles about WPF in general and some basic information on custom control development but I have yet to find a good article (or book) with in-depth coverage of custom control development in general and design-time related issues in particular.


Continue Reading...



I wanted to show the usage of these two very useful debugger attributes. If you don’t know them keep on reading, they are very useful.



This attribute allows you to customize the way an object is displayed. lets look at the following example:

Continue Reading...



Here is a problem that one of my colleagues who is just starting to use WPF got himself into. He was working on an application that displays items using an ItemsControl and uses a DataTemplate. Inside the DataTemplate he used an Image. Here is the Xaml code:


   1: <Window.Resources>
   2:         <Image Source="Creek.jpg" x:Key="IMG"></Image>
   3:     </Window.Resources>
   4:     <Grid>
   5:         <ItemsControl ItemsSource="{Binding}">
   6:             <ItemsControl.ItemTemplate>
   7:                 <DataTemplate>
   8:                     <Border BorderThickness="2" BorderBrush="Black" 
   9:                             CornerRadius="3" MinHeight="10">
  10:                         <ContentControl Content="{StaticResource IMG}"/>
  11:                     </Border>
  12:                 </DataTemplate>
  13:             </ItemsControl.ItemTemplate>
  14:         </ItemsControl>
  15:     </Grid>

This is a much simpler example, but the principal is the same.


Can you see what was he doing wrong?

Continue Reading...