How can I dynamically set the event handler for a TabItem when it is selected?

Posted by juharr on Stack Overflow See other posts from Stack Overflow or by juharr
Published on 2010-04-21T23:05:58Z Indexed on 2010/04/21 23:43 UTC
Read the original article Hit count: 536

Filed under:
|
|

In XAML you can do

<TabItem Selector.Selected="myEvenHandler"></TabItem>

to set the event handler for when that tab is selected. How can I do the exact same thing dynamically. I would prefer not to use the SelectionChanged event of TabControl if I can help it. Clearly there is a Selected event on the TabItem I just cannot seem to get at it in code. Here's what I'd like to do.

TabItem item = new TabItem();
MyCustomControl mcc = new MyCustomControl();
item.Content = mcc;
item.Selected += (s,e) =>  // This event does not exist
{
    selectedControl = mcc;
}
myTabControl.Items.Add(item);

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf