Reputation: 2965
I wanted to find a method of firing an event when the TabItem of a Page is selected. I had a look around and found that placing a Label on the header and using MouseLeftButtonDown
was a way of making this event fire. The XAML looks like this;
<TabItem>
<TabItem.Header>
<Label Content="Archived Jobs" MouseLeftButtonDown="CallArchivedJobsTabItemSelected"/>
</TabItem.Header>
</TabItem>
There is an issue with this fix though, in that if the user clicks in a specific place under the Label
they will be able to select the TabItem
without the event firing. How can I program this differently to ensure that they cannot bypass the event firing?
Upvotes: 0
Views: 414
Reputation: 1454
You could try to use SelectionChanged Event, it works pretty well. See example:
private void MyTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Console.WriteLine("You selected tab number {0}", MyTabControl.SelectedIndex);
}
Upvotes: 3