When a new item is added to the Flights collection a new TabItem is added to the TabControl. When a new tab is added, I need to call a method on the Chart control. The problem is I can’t figure out the right event to handle.
My XAML looks something like the following:
<TabControl Name="chartControl" ItemsSource="{Binding Flights}">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="{Binding Name}" />
</Style>
</TabControl.ItemContainerStyle>
<TabControl.ContentTemplate>
<DataTemplate>
<WindowsFormHost Name="winHost">
<legacy:Chart></legacy:Chart>
</WindowsFormHost>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
- I tried handling the
Loadedon theTabControl,
but duh that’s only fired once. - I attempted a
DataTemplate
Triggeron theRoutedEvent
FrameWorkElement.Loadedbut I’m pretty sure that’s not meant for my situation - I tried an EventSetter but that
didn’t quite work the way I want
either
I attempted a few other things, but I don’t quite remember them all.
Any suggestions would be greatly appreciated!
If I’m reading your XAML correctly, you are creating a single Chart control for the TabControl and changing its data when the TabItem changes? If so, you should be able to use the
SelectionChangedevent.You might be better off putting your Chart control in the ItemTemplate so it automatically loads the selected
Flightsdata when the user switches tabs or adds a new one.