• Home
  • About
  •  

    Databinding In Silverlight With New ItemContainerStyle

    May 16th, 2008

    Recently on OzSilverlight mailing list a question was asked about data-bindings. The issue was how do you use data-binding once you have replaced ItemContainerStyle for a ListBox.

    The answer is that you can replace the entire Template by giving it a new ControlTemplate and specify your bindings within the new template. I have created this example to illustrate this.

    I have two list boxes. The top one uses the normal process of setting DataTemplate, the bottom one uses a totally new template. Note that I set the ItemContainerStyle to be a style I have defined at UserControl level. This is what my markup looks like:

    image

    In my C# code I create a books collection and assign it to ItemsSource property of both list boxes:

    image

    Below is the output when I run the project:

    image

    Silverlight comes packed some powerful data-binding concepts. As you saw in this example that I have complete control over what my control looks like and at the same time I can also use data-binding features available to me.

    kick it on DotNetKicks.com

    Technorati Tags: ,