private void OnTabChanged(object sender, SelectionChangedEventArgs e) { PageItemViewModel selectedTab = NavControl.SelectedValue as PageItemViewModel; if (selectedTab == null) { return; } PageContainer selectedPage = selectedTab.Item.Content as PageContainer; if (selectedPage != null) { //Prevent handling over changing inside tab item if (currentTab == selectedPage) { return; } if (currentTab != null) { try { currentTab.OnClose(); } catch (AppDomainUnloadedException) { } } currentTab = selectedPage; currentTab.OnShow(); } }