1

Closed

TreeView jumps to last node when used inside a tab control and using complex headers for TreeViewItems

description

I have a simple Tab control with two tabs, one of them contains a tree.
 
The tree (TreeView) contains a couple of TreeViewItems, each of the uses a "complex" content for header - a StackPanel with a button and a textblock (sample code attached).
 
The scenario - run the app, click the first node to select it, move to tab no. 2, return to tab no. 1 - the selected node is not the last node.
 
It also seems that every node/item receives selected + unselected events (first unselected, second selected, second unselected, third selected and so on...)

file attachments

Closed Dec 24, 2008 at 10:46 PM by JustinJosefAngel
Thanks for reporting this.

Closing as duplicate to issue #1116:
http://www.codeplex.com/Silverlight/WorkItem/View.aspx?WorkItemId=1116

The temporary fix is (seems to be) to add the following code snippet:
tabControl.SelectionChanged += (s, e) =>
{
if (e.RemovedItems != null && e.RemovedItems.Count > 0)
{
    var tab = e.RemovedItems.Cast().First();
    if (tab.Content != null) (tab.Content as Control).IsEnabled = false;
}
if (e.AddedItems != null && e.AddedItems.Count > 0)
{
    var tab = e.AddedItems.Cast().First();
    if (tab.Content != null) (tab.Content as Control).IsEnabled = true;
}
};