OK, so I have a window called PictureWindow which displays pictures (I've cut out the code not related to making tabs). The TabControl is named "itemsTab". Using a button press, I can make a new tab no problem. But using the same operations inside a called method doesn't work. Using the buttonTab_Click method makes a new tab, the newTab method does not.
The only real difference I can see is due to the sender and RoutedEventArgs objects - how do these effect the operation here? Or is there something else I'm missing?
Thanks in advance.
Edit To make things even stranger, the newTab method does make a new tab, but only if it is called in the PictureWindow constructor method. If I have the following a new tab is made.
public PictureWindow(string current) { InitializeComponent(); newTab(current); }
But if I call the method anywhere else it doesn't work.
public partial class PictureWindow : Window { public PictureWindow(string current) { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { } private void buttonClose_Click(object sender, RoutedEventArgs e) { this.Close(); } private void buttonTab_Click(object sender, RoutedEventArgs e) { TabItem newTab = new TabItem(); newTab.Header = "New Tab!"; itemsTab.Items.Add(newTab); } public void newTab(string current) { TabItem newTab = new TabItem(); itemsTab.Items.Add(newTab); } }
var newWindow = new PictureWindow(fileName); var window = newWindow.getCurrentPictureWindow(); window.newTab(fileName);
By using the getCurrentPictureWindow to select the right window, the tab was added successfully. - Irish Yobbo