WPF MVVM and Showing Dialogs

Developing a WPF/Silverlight application using the MVVM (Model-View-ViewModel) pattern is a real challenge. But you know that using this pattern you write low-coupled and fully testable code (I hope). As MVVM says, the View can contain only XAML declarations. That is, no code-behind is present in your .xaml.cs file. Continue Reading…

Extending ItemsControl in WPF/Silverlight remark

Have you ever tried to extend ItemsControl in WPF/Silverlight? I guess the answer is Yes. In many situations you need to create a custom control, which support items. In this case you can use either ItemsControl or ListBox as a base. ItemsControl provides a couple of methods to help you build your items control. Such methods are IsItemItsOwnContainerOverride, GetContainerForItemOverride and PrepareContainerForItemOverride. When you add items to your control these methods are being called to help you manage your items. But have you run is such situation that when you added items these methods were not called? Well, it’s a very strange situation really. Here is you should make sure when you encounter this problem:

  • make sure you are extending ItemsControl
  • make sure your ItemsSource actually has items
  • make sure the control is visible
  • make sure you have put ItemsPresenter in the Template of your control

ItemsPresenter specifies where items should be placed, so always make sure you have placed it along other controls in the Template of your items control.

Timer vs. DispatcherTimer in WPF

Have you ever wondered what is the difference between Timer and DispatcherTimer in WPF / Silverlight? In this post I will try to explain you the little difference. Timer generates recurring events in an application. DispatcherTimer is a timer that is integrated into the Dispatcher queue which is processed at a specified interval of time and at a specified priority. Timers are not guaranteed to execute exactly when the time interval occurs, but are guaranteed not to execute before the time interval occurs. This is because DispatcherTimer operations are placed on the Dispatcher queue like other operations. When the DispatcherTimer operation executes, it is dependent of the other jobs in the queue and their priorities. Continue Reading…

Modifying the ListBox Control in Silverlight 2.0

I am going to show you how you can modify the standard ListBox control used in Silverlight 2.0. Many people want to change the default view of this control but they can’t remove the line between the items. If you download the code of the Silverlight control from the official site of Microsoft you will see that after every item there is a line. In this example I will show you how you can remove this line.

Let’s create e new Silverlight 2.0 application and place a ListBox in it.

Continue Reading…