开发者

Help with Binding tabcontrol that contains a treeview

开发者 https://www.devze.com 2023-02-21 08:31 出处:网络
In a silverlight project i have a class: class Foo{ List<Bar> Bars; string BarName; } In my view model, I have:

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 });
0

精彩评论

暂无评论...
验证码 换一张
取 消