Help with Binding tabcontrol that contains a treeview
In a silverlight project i have a class:
class Foo{
List<Bar> Bars;
string BarName;
}
In my view model, I have:
List<Foo> Foos;
My TabControl is bound to Foos, and I'm using a Con开发者_运维问答verter
to convert my Foo class to a TabItem, with Header = BarName
, and Content = Bars
My TabItem's content is just a TreeView, and I'd like to bind the TreeView's ItemSource to Bars
However I'm stuck trying to figure this out.
TabControl's ContentTemplate should be DataTemplate with TreeView and
<DataTemplate x:Key="ContentTemplate">
<sdk:TreeView ItemsSource={Binding}/>
</DataTemplate>
Update:
In code you can use template above:
yourTabItem.ContentTemplate = (DataTemplate)Application.Resources["ContentTemplate"];
Or without template:
yourTreeView.SetBinding(TreeView.ItemsSourceProperty, new Binding("Bars") { Source = yourSource });
精彩评论