I want to be able to access public members of my Window from within its TabControl Pages. To do that, I've tried switched from using XAML:
<TabControl TabStripPlacement="Left" HorizontalContentAlignment="Left" Name="wizardTabs">
<TabItem Header="Login">
<Frame Source="LoginPage.xaml" IsTabStop="False"/>
</TabItem>
</TabControl>
to code-based population of the tabs instead, during the Loaded event of the main window:
newFrame = new Frame();
newFrame.Source = new Uri(@"\LoginPage.xaml", UriKind.Relative);
newFrame.IsTabStop = false;
tabItem = new TabItem();
tabItem.Header = "Login";
tabItem.Content = newFrame;
wizardTabs.Items.Add(tabItem);
I'm using a Frame in the Tab and loading a XAML Page in the Frame. In this way, I thought that the constructor would be available to me so that I can pass a this pointer into the Page class:
LoginPage loginPage = newFrame.Content as LoginPage;
loginPage.parent = this;
but I have discovered that loading XAML requires an empty constructor. Also, newFrame.Content is always NULL. I'm thinking it's related to the fact that the XAML hasn't been loaded at this stage, but I can't figure out when that XAML load will be performed, and if it's later, how I can set the "parent" pointer.
Thanks for any suggestions. I'm a newbie WPF coder, so please guide me.