Setting DataContext in a Listbox Declaratively
Posted
by
Oscar
on Stack Overflow
See other posts from Stack Overflow
or by Oscar
Published on 2010-12-26T21:51:36Z
Indexed on
2010/12/26
23:54 UTC
Read the original article
Hit count: 534
Hi, I am a newbie in this Silverlight Databinding subject. I am starting to understand how cool is this declaratively way of data binding. To try it out, I have this listbox in my Page.xaml:
<ListBox Height="100" Name="lbCategories" Width="236" HorizontalAlignment="Left" Margin="20,0,0,0" SelectionMode="Multiple" ItemsSource="{Binding Categories}" DisplayMemberPath="Name" />
In my Page.xaml.cs I have a public property called Categories of the type ObservableCollection.
It works if this following line is present in my CS file:
DataContext = this;
But I want to avoid any programatically databinding. I would like to set the DataContext to "this" in my ListBox element declarativelly. Is there any way of doing that?
Thanks, Oscar
© Stack Overflow or respective owner