/// <summary> /// When the Popup closes we no longer need to monitor activation changes. /// </summary> /// <param name="sender">Instance that triggered the event.</param> /// <param name="e">Event data describing the conditions that led to the event.</param> private void OnPopupClosed(object sender, object e) { Window.Current.Activated -= OnWindowActivated; SettingsFlyout flyout = _settingsPopup.Child as SettingsFlyout; if (null != flyout) { flyout.SaveSettings(); } }
/// <summary> /// Event handler for the "App Settings" button added to the settings charm. This method /// is responsible for creating the Popup window will use as the container for our settings Flyout. /// The reason we use a Popup is that it gives us the "light dismiss" behavior that when a user clicks away /// from our custom UI it just dismisses. This is a principle in the Settings experience and you see the /// same behavior in other experiences like AppBar. /// </summary> /// <param name="command"></param> private void OnSettingsCommand(IUICommand command) { // Desired width for the settings UI. UI guidelines specify this should be 346 or 646 depending on your needs. const double SettingsWidth = 346; // Create a Popup window which will contain our flyout. _settingsPopup = new Popup(); _settingsPopup.Closed += OnPopupClosed; Window.Current.Activated += OnWindowActivated; _settingsPopup.IsLightDismissEnabled = true; _settingsPopup.Width = SettingsWidth; _settingsPopup.Height = _windowBounds.Height; // Add the proper animation for the panel. _settingsPopup.ChildTransitions = new TransitionCollection(); _settingsPopup.ChildTransitions.Add(new PaneThemeTransition() { Edge = (SettingsPane.Edge == SettingsEdgeLocation.Right) ? EdgeTransitionLocation.Right : EdgeTransitionLocation.Left }); // Create a SettingsFlyout the same dimenssions as the Popup. SettingsFlyout flyout = new SettingsFlyout(); flyout.Width = SettingsWidth; flyout.Height = _windowBounds.Height; // Place the SettingsFlyout inside our Popup window. _settingsPopup.Child = flyout; // Let's define the location of our Popup. _settingsPopup.SetValue(Canvas.LeftProperty, SettingsPane.Edge == SettingsEdgeLocation.Right ? (_windowBounds.Width - SettingsWidth) : 0); _settingsPopup.SetValue(Canvas.TopProperty, 0); _settingsPopup.IsOpen = true; }