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); } } }
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; } } }