Please help me, or show me direction. I have been searching net for this issue, but could not find answer for it.
I have TextBlock and by clicking in Text Block I am adding Tab Item to my Tab Control. Everything working fine except IS Selected= true; Tab Item is not being selected. I have to select it manually. Here is my code.
var tabControl = (sender as TextBlock).FindParent<TabControl>();
tabControl.Items.Add(new TabItem() { Header = "10 Last Documents", IsSelected = true, Content = rec, Width = 150 });
While casting from Button it is Ok. Please help me!
I can’t explain why it works with the cast coming from button. But I have seen such behavior quite often when you create UI elements and immediately want to change properties on it. Most often the UI isn’t constructed yet or in the process of being constructed which leads to blocking some message pipe.
Here’s a workaround to your issue:
Do your UI changes asynchronously via the dispatcher so the system gets enough time to create everything step by step and your IsSelected should be properly handled ….
Code: