积极答复者
【求助大难】WPF 的 TabControl 绑定不同的窗口集合

问题
-
代码里public static ObservableCollection<TabItem> ou = new ObservableCollection<TabItem>();
public void addB2(string Header, FrameworkElement fe)
{
TabItem t = new TabItem();
t.Header = Header;
t.Content = fe;
t.IsSelected = true;
ou.Add(t);
}这是一个各种窗口的集合(canvas,gird,图片,自定义控件等 就是不同任意的窗口),把他们都丢在上面这个集合里。
然后如何 把 XAML里的一个TabControl ,和这个集合绑定起来,达到效果
可以选中不同的Header 标题 ,可以正确的显示ou里不同的窗口的内容。
在网上没找到这方面的资料,求救 例子代码
- 已更改类型 黑心 2011年4月25日 4:03
- 已移动 Cookie Luo 2011年4月26日 5:11 (发件人:Visual C#)
答案
-
完成以下两步:
1) 定义你的TabControl:
<TabControl ItemsSource="{Binding}" Name="test"/>
2)然后 绑定你的TabControl和Collection:
test.ItemsSource = ou;
就可以正常显示了。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年4月26日 8:34
- 取消答案标记 黑心 2011年4月26日 8:35
- 已标记为答案 黑心 2011年4月26日 8:35
全部回复
-
完成以下两步:
1) 定义你的TabControl:
<TabControl ItemsSource="{Binding}" Name="test"/>
2)然后 绑定你的TabControl和Collection:
test.ItemsSource = ou;
就可以正常显示了。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年4月26日 8:34
- 取消答案标记 黑心 2011年4月26日 8:35
- 已标记为答案 黑心 2011年4月26日 8:35
-
你的那个方法里面“ t.IsSelected = true;” 这个是干什么的?
你现在的描述很乱,我们跟本没法给你做,你连自己要用什么方法实现都没定下来,只是对现象的不停的描述,我们该如何帮你呢?
我强烈建议你先看看TabControl如何使用的文章,然后再针对问题去问。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Sheldon _XiaoModerator 2011年4月26日 8:34
-
呵呵,解决就好。
我标记我的回复为答案了, 因为那个回复已经回答了你的原始问题。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.