Connoisseurs, please help in this question: There is a TabControl with 4 elements. When loading the form they are loaded all at once. How can I make a download of any TabItem only when I click on it (the method is already ready, you just need to call it when you click). (I rummaged through the whole Internet, nothing came up) At the moment, on all 4 TabItem's it’s worth Loaded="realm1(2,3,4)_Loaded" As a result, everyone is Loaded="realm1(2,3,4)_Loaded" .
- The task is only to call an arbitrary method when selecting an item with the ability to determine which order of items was clicked? - Sam
- When you click on the item, just call the method :) - Elizabeth
- What for do you need it? Are you not using MVVM? - VladD
|
1 answer
Tab selection in TabControl is actually the selection of an element from the list.
Xaml:
<TabControl SelectionChanged="Selector_OnSelectionChanged"> ... </TabControl> Code-behind:
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { // Обработка } In this case, the initial opening of the item will also be accompanied by a SelectionChanged event.
- Thank you, I will try - Elizabeth
- Unfortunately, this did not work (I have methods on each tab that load the information on the content, and they should load only if they clicked on the tab. As a result, the program still loads all the tabs at once - Elizaveta
- Do you need to programmatically load all the contents of this tab when clicking on a tab? Why not do it in the
SelectionChangedhandler, by pulling information about the pressed tab and checking some of its own flag, was this tab already loaded? - Sam - I am not experienced in these matters (each tab loads separate content from me, how to determine which one is clicked? Or to determine if it is pressed and to load the content? - Elizaveta
- I have my own methods for each tab - 4 tabs and 4 methods, I don’t want them to load as soon as the program is loaded - Elizaveta
|