miércoles, 26 de enero de 2011

Silverlight Right Mouse Button

In Silverlight 4, there is a new feature very useful for so many scenarios. This is the right mouse button characteristic that you normally use to show a context menu. But there are some things that you have to take into account.

martes, 25 de enero de 2011

Retrieve items elements within ListBox control

In this post, I will show a simple method in order to retrieve the container items elements in a ListBox control by using ItemContainerGenerator.

foreach (var item in this.listBox.Items)
{
      var container = this.listBox.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
      if (container != null)
      {
           VisualStateManager.GoToState(container, "Highlighted", true);
       }
}

As you can see, in container element, you will receive the ListBoxItem (or the container that you are using). This is a very simple operation in comparison with some other that you can find by web where you may read that you need to use VisualTreeHelper or navigate among elements until find the container or some other things.