private void OnLoaded(object sender, RoutedEventArgs e) { if (selectedContact == null && Contacts.Count > 0) { selectedContact = Contacts[0]; MasterListView.SelectedIndex = 0; } // If the app starts in narrow mode - showing only the Master listView - // it is necessary to set the commands and the selection mode. if (PageSizeStatesGroup.CurrentState == NarrowState) { VisualStateManager.GoToState(this, MasterState.Name, true); } else if (PageSizeStatesGroup.CurrentState == WideState) { // In this case, the app starts is wide mode, Master/Details view, // so it is necessary to set the commands and the selection mode. VisualStateManager.GoToState(this, MasterDetailsState.Name, true); MasterListView.SelectionMode = ListViewSelectionMode.Extended; MasterListView.SelectedItem = selectedContact; } else { new InvalidOperationException(); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); SelectedContact = e.Parameter as Contact; // Register for hardware and software back request from the system SystemNavigationManager.GetForCurrentView().BackRequested += OnHardwareBackRequested; }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); SelectedContact = e.Parameter as Contact; // Register for hardware and software back request from the system SystemNavigationManager systemNavigationManager = SystemNavigationManager.GetForCurrentView(); systemNavigationManager.BackRequested += OnBackRequested; systemNavigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; }
private void AddItem(object sender, RoutedEventArgs e) { Contact c = Contact.GetNewContact(); Contacts.Add(c); // Select this item in case that the list is empty if (MasterListView.SelectedIndex == -1) { MasterListView.SelectedIndex = 0; selectedContact = MasterListView.SelectedItem as Contact; // Details view is collapsed, in case there is not items. // You should show it just in case. DetailContentPresenter.Visibility = Visibility.Visible; } }
private void DeleteItem(object sender, RoutedEventArgs e) { if (selectedContact != null) { Contacts.Remove(selectedContact); if (MasterListView.Items.Count > 0) { MasterListView.SelectedIndex = 0; selectedContact = MasterListView.SelectedItem as Contact; } else { // Details view is collapsed, in case there is not items. DetailContentPresenter.Visibility = Visibility.Collapsed; } } }
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (PageSizeStatesGroup.CurrentState == WideState) { if (MasterListView.SelectedItems.Count == 1) { selectedContact = MasterListView.SelectedItem as Contact; EnableContentTransitions(); } // Entering in Extended selection else if (MasterListView.SelectedItems.Count > 1 && MasterDetailsStatesGroup.CurrentState == MasterDetailsState) { VisualStateManager.GoToState(this, ExtendedSelectionState.Name, true); } } // Exiting Extended selection if (MasterDetailsStatesGroup.CurrentState == ExtendedSelectionState && MasterListView.SelectedItems.Count == 1) { VisualStateManager.GoToState(this, MasterDetailsState.Name, true); } }
// ItemClick event only happens when user is a Master state. In this state, // selection mode is none and click event navigates to the details view. private void OnItemClick(object sender, ItemClickEventArgs e) { // The clicked item it is the new selected contact selectedContact = e.ClickedItem as Contact; if (PageSizeStatesGroup.CurrentState == NarrowState) { // Go to the details page and display the item Frame.Navigate(typeof(DetailsPage), selectedContact, new DrillInNavigationTransitionInfo()); } //else { // Play a refresh animation when the user switches detail items. //EnableContentTransitions(); } }
private void DeleteItems(object sender, RoutedEventArgs e) { if (MasterListView.SelectedIndex != -1) { List<Contact> selectedItems = new List<Contact>(); foreach (Contact contact in MasterListView.SelectedItems) { selectedItems.Add(contact); } foreach (Contact contact in selectedItems) { Contacts.Remove(contact); } if (MasterListView.Items.Count > 0) { MasterListView.SelectedIndex = 0; selectedContact = MasterListView.SelectedItem as Contact; } else { DetailContentPresenter.Visibility = Visibility.Collapsed; } } }