简体   繁体   中英

WPF - how to call mainwindow tabitems from inside a control

I have tabcontrol in my main window. The different tbas I create with custom controls (for edit, addition etc.). I want to be able to address the other tabs from inside the control, so that when, for example, I click submit at some of the forms, it activates a specific other tab.

I tried with

       BaseWindow n = new BaseWindow();
        n.SearchTab.Visibility = System.Windows.Visibility.Hidden;

Still obviously this does not do the trick.

Any ideas?

I would consider reworking your architecture here.

One option would be to have your custom controls (UserControls?) inside of the tabs expose a Routed Event . Your main Window could then subscribe to the routed events (at the main window's level) and handle the application navigation.

This is much cleaner, from a design standpoint, since the user controls don't need to know about other controls, they just say "I hit this button", and the main window decides that event means to show the other window. If you ever change your tabs around, you won't break everything, since this keeps the coupling lower between your tabs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM