【发布时间】:2012-04-12 13:02:53
【问题描述】:
我有以下代码:
private Dictionary<int, UserControl> tabControls = new Dictionary<int, UserControl>();
public MainWindow()
{
InitializeComponent();
tabControls[0] = new Panel1();
tabControls[1] = new Panel2();
tabControls[2] = new Panel3();
tabControls[3] = new Panel4();
tabControls[4] = new Panel5();
tabControls[5] = new Panel6();
tabControls[6] = new Panel7();
tabControls[7] = new Panel8();
}
public object SelectedTab
{
//this is assigned from xaml binding
set
{
OnCurrentTabChanged(tabControl.SelectedIndex);
}
}
void OnCurrentTabChanged(int tabIndex)
{
if (dataDisplay != null)
{
dataDisplay.Children.Clear();
dataDisplay.Children.Add(tabControls[tabIndex]);
}
}
每次用户选择不同的选项卡时,都会出现另一个控件。
有没有什么方法可以使用 xaml 来简化这个过程?
我不能将控件本身放在选项卡控件中
【问题讨论】:
-
将
<TabItem>s 添加到您的<TabControl>有什么问题? You could put the panels inside tab items, and the inactive ones will hide when a different tab is selected.我错过了什么吗?..