public void PositionAndShow(Window relativeTo, AppExpandedEventArgs e) { var taskbarState = WindowsTaskbar.Current; var HEADER_SIZE = (double)App.Current.Resources["DeviceTitleCellHeight"]; var ITEM_SIZE = (double)App.Current.Resources["AppItemCellHeight"]; var PopupBorderSize = (Thickness)App.Current.Resources["PopupBorderThickness"]; var volumeListMargin = (Thickness)App.Current.Resources["VolumeAppListMargin"]; DataContext = e.ViewModel; var contextTheme = (string)relativeTo.TryFindResource("ContextMenuTheme"); _useDarkTheme = contextTheme != null && contextTheme.Equals("DarkOnly"); Point offsetFromWindow = e.Container.TranslatePoint(new Point(0, 0), relativeTo); // Adjust for the title bar, top border and top margin on the app list. offsetFromWindow.Y -= (HEADER_SIZE + volumeListMargin.Bottom + PopupBorderSize.Top); var popupHeight = (HEADER_SIZE + (e.ViewModel.ChildApps.Count * ITEM_SIZE) + volumeListMargin.Bottom + volumeListMargin.Top); var popupOriginYScreenCoordinates = (relativeTo.PointToScreen(new Point(0, 0)).Y / this.DpiHeightFactor()) + offsetFromWindow.Y; var scaledWorkArea = new Rect(taskbarState.ContainingScreen.WorkingArea.Left / this.DpiWidthFactor(), taskbarState.ContainingScreen.WorkingArea.Top / this.DpiHeightFactor(), taskbarState.ContainingScreen.WorkingArea.Width / this.DpiWidthFactor(), taskbarState.ContainingScreen.WorkingArea.Height / this.DpiHeightFactor() ); // If we flow off the bottom if (popupOriginYScreenCoordinates + popupHeight > scaledWorkArea.Bottom) { popupOriginYScreenCoordinates = scaledWorkArea.Bottom - popupHeight; // If we also flow off the top if (popupOriginYScreenCoordinates < scaledWorkArea.Top) { popupOriginYScreenCoordinates = scaledWorkArea.Top; popupHeight = scaledWorkArea.Bottom - scaledWorkArea.Top; } } Placement = PlacementMode.Absolute; HorizontalOffset = (relativeTo.PointToScreen(new Point(0, 0)).X / this.DpiWidthFactor()) + offsetFromWindow.X; VerticalOffset = popupOriginYScreenCoordinates; Width = ((FrameworkElement)e.Container).ActualWidth; Height = popupHeight; ShowWithAnimation(); }
private void ViewModel_AppExpanded(object sender, AppExpandedEventArgs e) { AppPopup.PositionAndShow(this, e); }
private void ViewModel_AppExpanded(object sender, AppExpandedEventArgs e) { Trace.WriteLine("FullWindow ViewModel_AppExpanded"); AppPopup.PositionAndShow(_mainViewModel, this, e); }