views:

101

answers:

0

I am able to create new TabItems with Content dynamically to a new window by streaming the Xaml with XamlReader:

NewWindow newWindow = new NewWindow();
newWindow.Show();                
TabControl myTabCntrol = newWindow.FindName("GBtabControl") as TabControl;
StringReader stringReader = new StringReader(XamlGrid);
XmlReader xmlReader = XmlReader.Create(stringReader);

TabItem myTabItem = new TabItem();
myTabItem.Header = qDealName;
myTabItem.Content = (UIElement)XamlReader.Load(xmlReader);

myTabCntrol.Items.Add(myTabItem);

This works fine. It displays a new grid wrapped in a scrollviewer. The problem is access the TabItem content from the newWindow.

TabItem ti = GBtabControl.SelectedItem as TabItem;
string scrollvwnm = "scrollViewer" + ti.Header.ToString();
MessageBox.Show(ti.ActualHeight.ToString()); // returns 21.5            
ScrollViewer scrlvwr = this.FindName(scrollvwnm) as ScrollViewer;
MessageBox.Show(scrollvwnm); // Displays name double checked for accuracy    
MessageBox.Show(scrlvwr.ActualHeight.ToString()); //Crashes
ScrollViewer scrlvwr = ti.FindName(scrollvwnm) as ScrollViewer;
MessageBox.Show(scrollvwnm); // Displays name double checked for accuracy    
MessageBox.Show(scrlvwr.ActualHeight.ToString()); //Also Crashes

Is there a method to refresh UI in XAML so the new window is able to access the newly loaded tab item content?

Thanks