1
我正在製作一個應用程序,其中我在選項卡控件中打開wpf頁面。但是我可以在tabcontrol中一次又一次打開相同的頁面。我想,如果一旦打開頁面,它不能再次打開,如果我嘗試再次打開,它應該關注tabcontrol。我做了下面的代碼,但沒有工作。我正在使用自定義closableTabItem用戶控件。防止TabControl中的頁面的多個實例
private void Set_Fee_Click(object sender, RoutedEventArgs e)
{
// Adding page to frame and then adding that frame to tab item and then adding tab item to main tab.
FeeStructure feePage = new FeeStructure();
_closableTab = new ClosableTabItem();
_formFrame = new Frame();
_formFrame.Content = feePage;
_closableTab.Content = _formFrame;
_closableTab.Header = "Set Fee Structure";
if (!mainTab.Items.Contains(_closableTab))
{
mainTab.Items.Add(_closableTab);
_closableTab.Focus();
}
else
{
_closableTab.Focus();
}
}
private void Database_RecoveryBackup_Click(object sender, RoutedEventArgs e)
{
// Adding page to frame and then adding that frame to tab item and then adding tab item to main tab.
DbRecoveryBackup dbRecBack = new DbRecoveryBackup();
_closableTab = new ClosableTabItem();
_formFrame = new Frame();
_formFrame.Content = dbRecBack;
_closableTab.Content = _formFrame;
_closableTab.Header = "Data Base";
if (!mainTab.Items.Contains(_closableTab))
{
mainTab.Items.Add(_closableTab);
_closableTab.Focus();
}
else
{
_closableTab.Focus();
}
}
'f是ClosableTabItem '會工作得更快。或'Items.OfType()。Any()' –
abatishchev
@abatishchev更正。 – Code0987