private void OnTapped(object sender, TappedRoutedEventArgs e) { FlyoutBase flyoutBase = FlyoutBase.GetAttachedFlyout(this); if (flyoutBase != null) { Flyout flyout = flyoutBase as Flyout; if (flyout != null) { if (this.IsFullWidthFlyoutEnabled) { flyout.Placement = ResponsiveHelper.GetPopupPlacement(); } else { flyout.Placement = FlyoutPlacementMode.Bottom; } if (flyout.Content is IFlyoutContent) { ((IFlyoutContent)flyout.Content).HandleFlyout(flyout); } } flyoutBase.ShowAt(this); } }
private static void OnTapped(object sender, TappedRoutedEventArgs e) { try { FrameworkElement frameworkElement = (FrameworkElement)sender; FlyoutBase flyoutBase = FlyoutBase.GetAttachedFlyout(frameworkElement); if (flyoutBase != null) { Flyout flyout = flyoutBase as Flyout; if (flyout != null) { flyout.Placement = ResponsiveHelper.GetPopupPlacement(); if (flyout.Content is IFlyoutContent) { ((IFlyoutContent)flyout.Content).HandleFlyout(flyout); } } flyoutBase.ShowAt(frameworkElement); } } catch (Exception ex) { var messageBoxService = Ioc.Resolve <IMessageBoxService>(); messageBoxService.ShowAsync( StringResources.Message_Information, "It looks like 2Day is having trouble here - that seems due to the latest Windows 10 Mobile insiders build. You can change due date by sliding left a task in the task list for now :-)"); TrackingManagerHelper.Exception(ex, "OpenFlyoutOnTap.OnTapped"); throw; } }
private void OnFolderNameTapped(object sender, TappedRoutedEventArgs e) { if (ResponsiveHelper.IsUsingSmallLayout()) { this.ShowQuickNavBar(); } else { if (this.viewModel.SelectedFolder != null) { this.SelectionManager.ToogleTaskSelection(this.viewModel.SelectedFolder.Tasks.ToList()); } } }
private void OnBtnTapped(object sender, TappedRoutedEventArgs e) { var button = (Button)sender; // remove event handler because we need this code to run only once button.Tapped -= this.OnBtnTapped; // call FindName so that the target element is lazily loaded (thanks to BtnPriorityFlyoutContent) this.FindName(button.Name + "FlyoutContent"); if (button.Name == "BtnAddTags" && !ResponsiveHelper.IsUsingSmallLayout()) { this.ScrollViewerTags.MaxHeight = 250; } }
private void OnLoaded(object sender, RoutedEventArgs e) { if (ResponsiveHelper.IsUsingSmallLayout()) { var children = this.LayoutRoot.Children.ToList(); this.LayoutRoot.Children.Clear(); var stackPanel = new StackPanel(); foreach (var child in children) { stackPanel.Children.Add(child); } this.Content = stackPanel; } }
private static void OnPopupLayoutUpdated(object sender, object e) { if (currentPopup == null) { return; } currentPopup.LayoutUpdated -= OnPopupLayoutUpdated; Page page = TreeHelper.FindVisualAncestor <Page>(currentPopup); if (page == null || !(currentPopup.Child is FrameworkElement)) { return; } Point popupLocation = currentPopup.TransformToVisual(page).TransformPoint(new Point()); FrameworkElement popupChild = (FrameworkElement)currentPopup.Child; double popupWidth = popupChild.ActualWidth; double popupHeight = popupChild.ActualHeight; if (ResponsiveHelper.IsUsingSmallLayout()) { // align verticaly and horizontally double newHorizontalOffset = (Window.Current.Bounds.Width - popupWidth) / 2; double newVerticalOffset = (Window.Current.Bounds.Height - popupHeight) / 2; currentPopup.HorizontalOffset = -popupLocation.X + newHorizontalOffset; currentPopup.VerticalOffset = -popupLocation.Y + newVerticalOffset; } else if (popupLocation.Y + popupChild.ActualHeight >= Window.Current.Bounds.Height) { // popup doesn't fit vertically: // - it's not too close to the bottom of the page (otherwise it will open upward and we're fine) // - it's going to be displaye double newVerticalOffset = (Window.Current.Bounds.Height - popupHeight) / 2; currentPopup.HorizontalOffset = 0; currentPopup.VerticalOffset = -popupLocation.Y + newVerticalOffset; } else { // don't do anything currentPopup.HorizontalOffset = 0; currentPopup.VerticalOffset = 0; } currentPopup = null; }
private void OnContentLoaded(object sender, object e) { Page page = TreeHelper.FindVisualAncestor <Page>(this.owner); if (page == null || !(this.popup.Child is FrameworkElement)) { return; } Point relativeToPage = this.popup.TransformToVisual(page).TransformPoint(emptyPoint); FrameworkElement popupChild = (FrameworkElement)this.popup.Child; double popupWidth = popupChild.ActualWidth; bool isUsingSmallLayout = ResponsiveHelper.IsUsingSmallLayout(); if (isUsingSmallLayout) { if (Window.Current != null && popupChild.ActualHeight >= 150) { // small layout with large popup => center in screen Rect bounds = Window.Current.Bounds; popupChild.Height = bounds.Height; this.popup.HorizontalOffset = 0; this.popup.VerticalOffset = 0; var dateTimePicker = TreeHelper.FindVisualChild <DateTimePicker2>(popupChild); if (dateTimePicker != null) { dateTimePicker.VerticalAlignment = VerticalAlignment.Center; } } } else if (page.Width > 0) { this.popup.HorizontalOffset = -relativeToPage.X + (page.Width - popupWidth) / 2; } // check if the popup is not going to be shown out of screen vertically if (this.popup.VerticalOffset > 0 && Window.Current != null) { Rect bounds = Window.Current.Bounds; if (this.popup.VerticalOffset + popupChild.ActualHeight > bounds.Height) { this.popup.VerticalOffset -= (this.popup.VerticalOffset + popupChild.ActualHeight - bounds.Height); } } }
private void SetupWrapGrid() { if (this.wrapGrid == null) { return; } bool singleColumn; if (ResponsiveHelper.IsUsingSmallLayout()) { double w = this.ActualWidth; this.wrapGrid.ItemWidth = w; //this.popupBorder.Width = w; this.wrapGrid.MaximumRowsOrColumns = 1; singleColumn = true; } else { double w = this.ActualWidth; this.wrapGrid.ItemWidth = w / 2 - 12; //this.popupBorder.Width = w; this.wrapGrid.MaximumRowsOrColumns = 2; singleColumn = false; } var enumerable = this.ItemsSource as IEnumerable <object>; if (enumerable != null) { this.gridView.SelectionChanged -= this.OnGridViewSelectionChanged; var itemsSource = singleColumn ? new List <object>(enumerable) : enumerable.AlternateTwoColumns(); if (this.CreateItemCommand != null) { itemsSource.Add(this.CreateItemText); } this.gridView.ItemsSource = itemsSource; this.gridView.SelectionChanged += this.OnGridViewSelectionChanged; } }
protected override void OnApplyTemplate() { var textblock = (TextBlock)this.GetTemplateChild("PART_Title"); var backButton = (Button)this.GetTemplateChild("PART_BackButton"); var outterBorder = (Border)this.GetTemplateChild("PART_OutterBorder"); var grid = (Grid)this.GetTemplateChild("PART_Grid"); var content = (ContentControl)this.GetTemplateChild("PART_Content"); textblock.Text = this.Text; // if flyout is shown as flyout and not in a full page, add a left border if (this.Parent is FrameworkElement && ((FrameworkElement)this.Parent).Parent is Popup) { outterBorder.Margin = new Thickness(0, 1, 0, 0); outterBorder.BorderThickness = new Thickness(1, 0, 0, 0); } if (ResponsiveHelper.IsUsingSmallLayout()) { grid.RowDefinitions[0].Height = new GridLength(30); this.HeaderBackground = this.FindResource <SolidColorBrush>("HeaderBackgroundBrush"); textblock.Style = this.FindResource <Style>("PageHeaderTextBlockStyle"); textblock.Foreground = new SolidColorBrush(Colors.White); textblock.Text = textblock.Text.ToUpperInvariant(); backButton.Visibility = Visibility.Collapsed; var currentInnerMargin = content.Margin; content.Margin = new Thickness(currentInnerMargin.Left, 20, currentInnerMargin.Right, currentInnerMargin.Bottom); } else { textblock.Style = this.FindResource <Style>("PageHeaderNormalFlyoutTextBlockStyle"); backButton.Tapped += (s, e) => { Ioc.Resolve <INavigationService>().GoBack(); }; } }
public void Show(ToastType type, bool cancel = false) { this.MinWidth = 300; if (ResponsiveHelper.IsUsingSmallLayout()) { this.MaxWidth = double.MaxValue; this.borderThiness = new Thickness(0, 1, 0, 0); } else { this.MaxWidth = 300; this.borderThiness = new Thickness(1, 1, 1, 0); } this.ToastType = type; this.cancelSymbol.Visibility = cancel ? Visibility.Visible : Visibility.Collapsed; if (this.IsAnimated) { this.progressRing.Visibility = Visibility.Visible; this.progressRing.IsActive = true; this.icon.Visibility = Visibility.Collapsed; } else { this.progressRing.Visibility = Visibility.Collapsed; this.icon.Visibility = Visibility.Visible; } // at init of after slide down animation opacity is set to 0 if (this.Opacity == 0) { this.Opacity = 1; this.IsAnimationRunning = false; this.slideUpStoryboard.Begin(); } }
private void OnLoaded(object sender, RoutedEventArgs e) { if (ResponsiveHelper.IsUsingSmallLayout()) { this.CustomCommandBar.Visibility = Visibility.Collapsed; } else { var page = this.FindParent <Page>(); if (page != null) { var commandBar = page.BottomAppBar as CommandBar; if (commandBar != null) { var appBarButtons = commandBar.PrimaryCommands.OfType <AppBarButton>().ToList(); commandBar.PrimaryCommands.Clear(); foreach (var child in appBarButtons) { this.CustomCommandBarGrid.Children.Add(child); // the following is a nasty hack to hide the textual description of the AppBarButton in the new CustomCommandBarGrid grid child.Loaded += (s, e1) => { var textBlocks = TreeHelper.FindVisualChildren <TextBlock>(child); foreach (var textBlock in textBlocks) { if (textBlock.Name == "TextLabel" || textBlock.Name == "OverflowTextLabel") { textBlock.Visibility = Visibility.Collapsed; } } }; } commandBar.Visibility = Visibility.Collapsed; } } } }
private void SetupWrapGrid() { if (this.wrapGrid == null) { return; } bool singleColumn; if (ResponsiveHelper.IsUsingSmallLayout()) { double w = this.ActualWidth; this.wrapGrid.ItemWidth = w; this.popupBorder.Width = w; this.wrapGrid.MaximumRowsOrColumns = 1; singleColumn = true; } else { double w = this.ActualWidth + 50; this.wrapGrid.ItemWidth = w / 2 - 6; this.popupBorder.Width = w; this.wrapGrid.MaximumRowsOrColumns = 2; singleColumn = false; } var enumerable = this.ItemsSource as IEnumerable <object>; if (enumerable != null) { this.gridView.SelectionChanged -= this.OnGridViewSelectionChanged; this.gridView.ItemsSource = singleColumn ? enumerable : enumerable.AlternateTwoColumns(); this.gridView.SelectionChanged += this.OnGridViewSelectionChanged; } }
public void Initialize(UIElement owner) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); } this.owner = (FrameworkElement)owner; this.owner.DataContextChanged += (s, e) => { // the Content of this flyout is disconnected from the visual tree so we have to "plug" the datacontext manually if (this.Content != null) { this.Content.DataContext = this.owner.DataContext; } }; this.popup = new Popup { IsLightDismissEnabled = true, ChildTransitions = new TransitionCollection() }; this.popup.Closed += OnPopupClosed; this.popup.ChildTransitions.Add(new PaneThemeTransition { Edge = EdgeTransitionLocation.Top }); bool isUsingSmallLayout = ResponsiveHelper.IsUsingSmallLayout(); var popupChild = new Border { BorderBrush = this.FindResource <SolidColorBrush>("AppFlyoutBorderBrush"), Background = this.FindResource <SolidColorBrush>("AppFlyoutButtonBackgroundBrush"), Child = this.Content, }; if (isUsingSmallLayout) { if (Window.Current != null) { Rect bounds = Window.Current.Bounds; popupChild.Width = bounds.Width; } else { popupChild.Width = 320; } popupChild.BorderThickness = new Thickness(0, 1, 0, 1); } else { popupChild.Width = (double)SettingsSizeMode.Small; popupChild.BorderThickness = new Thickness(1); } this.popup.Child = popupChild; if (this.Content != null) { this.Content.Loaded += this.OnContentLoaded; } this.owner.Tapped += (s, e) => this.Show(e.OriginalSource as FrameworkElement); }
private void OnContentLoaded(object sender, object e) { Page page = TreeHelper.FindVisualAncestor <Page>(this.owner); if (page == null || !(this.popup.Child is FrameworkElement)) { return; } Point relativeToPage = this.popup.TransformToVisual(page).TransformPoint(emptyPoint); FrameworkElement popupChild = (FrameworkElement)this.popup.Child; double popupWidth = popupChild.ActualWidth; bool isUsingSmallLayout = ResponsiveHelper.IsUsingSmallLayout(); if (isUsingSmallLayout) { if (Window.Current != null && popupChild.ActualHeight >= 150) { // small layout with large popup => center in screen Rect bounds = Window.Current.Bounds; popupChild.Height = bounds.Height; this.popup.HorizontalOffset = 0; this.popup.VerticalOffset = 0; var dateTimePicker = TreeHelper.FindVisualChild <DateTimePicker2>(popupChild); if (dateTimePicker != null) { dateTimePicker.VerticalAlignment = VerticalAlignment.Center; } //Prevent Frequency Picker Cancel/Accept buttons from appearing under Windows Mobile Nav Bar var frequencyPicker2 = TreeHelper.FindVisualChild <FrequencyPicker2>(popupChild); if (frequencyPicker2 != null) { var currentMargins = frequencyPicker2.Margin; var navBarOffset = (bounds.Height - Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds.Bottom); if (currentMargins.Bottom < navBarOffset) { var newMargin = new Thickness(currentMargins.Left, currentMargins.Top, currentMargins.Right, currentMargins.Bottom + navBarOffset); frequencyPicker2.Margin = newMargin; } } } } else if (page.Width > 0) { this.popup.HorizontalOffset = -relativeToPage.X + (page.Width - popupWidth) / 2; } // check if the popup is not going to be shown out of screen vertically if (this.popup.VerticalOffset > 0 && Window.Current != null) { Rect bounds = Window.Current.Bounds; if (this.popup.VerticalOffset + popupChild.ActualHeight > bounds.Height) { this.popup.VerticalOffset -= (this.popup.VerticalOffset + popupChild.ActualHeight - bounds.Height); } } }
public async Task Show([NotNull] Action <FlyoutControl> removeHandler) { if (removeHandler == null) { throw new ArgumentNullException(nameof(removeHandler)); } this.removeHandler = removeHandler; Rect windowBounds = GetWindowVisibleBounds(); // Create a Popup window which will contain our flyout. this.settingsPopup = new Popup(); this.settingsPopup.Closed += this.OnPopupClosed; Window.Current.Activated += this.OnWindowActivated; Window.Current.SizeChanged += this.OnWindowSizeChanged; double flyoutWidth = (double)this.Size; this.settingsPopup.IsLightDismissEnabled = !this.staysOpen; this.settingsPopup.Width = flyoutWidth; this.settingsPopup.Height = windowBounds.Height; // We have some weird stuff when 2Day is running with continuum, basically we need a higher top margin because it looks like the // ApplicationView.GetForCurrentView().VisibleBounds include some viewport's height that is not included for standard mobile/tablet/desktop if (!ResponsiveHelper.IsInContinuum()) { this.topMargin = 30; this.settingsPopup.Height -= this.topMargin; } else { this.topMargin = 30 + 24; // 24 is the additional top margin we're adding for continuum this.settingsPopup.Height -= 30; } // Add the proper animation for the panel. this.settingsPopup.ChildTransitions = new TransitionCollection { new PaneThemeTransition { Edge = this.DockOnLeft ? EdgeTransitionLocation.Left : EdgeTransitionLocation.Right } }; // Create a SettingsFlyout the same dimensions as the Popup. var pane = this.Content as FrameworkElement; pane.Width = flyoutWidth; pane.Height = this.settingsPopup.Height; if (pane.Parent is Popup) { ((Popup)pane.Parent).Child = null; // delay to make sure the pane gets disconnected from its parent await Task.Delay(TimeSpan.FromMilliseconds(100)); } // Place the SettingsFlyout inside our Popup window. this.settingsPopup.Child = pane; // Let's define the location of our Popup. this.settingsPopup.SetValue(Canvas.LeftProperty, this.DockOnLeft ? 0 : (windowBounds.Width - flyoutWidth)); this.settingsPopup.SetValue(Canvas.TopProperty, this.topMargin); this.settingsPopup.IsOpen = true; }
private void HandleTap(TappedRoutedEventArgs e) { Point tappedPoint = e.GetPosition(this); ITextRange textRange = this.Document.GetRangeFromPoint(tappedPoint, PointOptions.ClientCoordinates); textRange.StartOf(TextRangeUnit.Link, true); if (textRange.Character != '\r' && textRange.CharacterFormat.Underline == UnderlineType.Single) { string content; this.Document.GetText(TextGetOptions.None, out content); textRange.StartPosition--; textRange.EndPosition++; while (!(textRange.Text.StartsWith(" ") || textRange.Text.StartsWith("\r")) && textRange.StartPosition > 0) { textRange.StartPosition--; } while (!(textRange.Text.EndsWith(" ") || textRange.Text.EndsWith("\r")) && textRange.EndPosition < content.Length) { textRange.EndPosition++; } this.link = textRange.Text; if (!string.IsNullOrWhiteSpace(this.link)) { this.link = this.link.Trim(' '); this.link = this.link.Trim('\r'); if (!this.link.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && !this.link.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { this.link = "http://" + this.link; } if (this.openLinkPopup == null) { this.openLinkPopup = new Popup { IsLightDismissEnabled = true, Child = new HyperlinkPopupContent() }; } this.openLinkPopup.IsOpen = false; ((HyperlinkPopupContent)this.openLinkPopup.Child).Hyperlink = this.link; var frame = Window.Current.Content as Frame; if (frame != null && frame.Content is Page) { var page = frame.Content as Page; var position = e.GetPosition(page); this.openLinkPopup.VerticalOffset = position.Y; if (ResponsiveHelper.IsUsingSmallLayout()) { this.openLinkPopup.HorizontalOffset = 15; ((HyperlinkPopupContent)this.openLinkPopup.Child).MaxWidth = 292; } else { this.openLinkPopup.HorizontalOffset = position.X; } } this.openLinkPopup.IsOpen = true; } } }