Setting DataContext in a Listbox Declaratively
- by Oscar
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