New TabItem Content ActualHeight crashes Xaml Window

Posted by Jack Navarro on Stack Overflow See other posts from Stack Overflow or by Jack Navarro
Published on 2010-03-23T22:11:07Z Indexed on 2010/03/23 22:13 UTC
Read the original article Hit count: 317

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about xaml

Related posts about uielement