timheuer / callisto

A control toolkit for Windows 8 XAML applications. Contains some UI controls to make it easier to create Windows UI style apps for the Windows Store in accordance with Windows UI guidelines.
http://timheuer.com/blog/archive/2012/05/31/introducing-callisto-a-xaml-toolkit-for-metro-apps.aspx
Other
338 stars 108 forks source link

Flyout placement is wrong if HostPopup's parent is set. #82

Closed lukasf closed 12 years ago

lukasf commented 12 years ago

If I add the host popup to the layout root, then the flyout's placement is off. The offset values from the popup are not interpreted as relative to the window but relative to the parent control, if a parent is set.

This can be easily fixed with the following code in PerformPlacement:

        ...
        // fix placement if popup's parent is set
        UIElement parent = _hostPopup.Parent as UIElement;
        if (parent != null)
        {
            var transform = parent.TransformToVisual(Window.Current.Content);
            var offset = transform.TransformPoint(new Point(0, 0));
            calcH -= offset.X;
            calcY -= offset.Y;
        }

        // now assign offset values
        _hostPopup.HorizontalOffset = calcH;
        _hostPopup.VerticalOffset = calcY;
        ...

Cheers, Lukas

timheuer commented 12 years ago

Can you provide me with a repro project showing the issue? The test app has one that roots it to the frame root and it works fine...so I want to make sure I understand the fix. Thanks for this though!

lukasf commented 12 years ago

Change ShowFlyoutMenu2 like below and then click "Show Menu". Placement will be offset by some amount. Changing as per my suggestion fixes the placement issue. I think in ShowFlyoutMenu3 it only works because there it is parented to the application's root grid, which fills the whole sceen. Then there will be no offset issues. This only appears if the parent does not cover the whole window.

Here I set the Parent to the LayoutRoot of the sample page, which is positioned next to the sample selection menu:

private void ShowFlyoutMenu2(object sender, RoutedEventArgs e)         {             Flyout f = new Flyout();             LayoutRoot.Children.Add(f.HostPopup);

            Border b = new Border();             b.Width = 300;             b.Height = 125;

            TextBlock tb = new TextBlock();             tb.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;             tb.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;             tb.TextWrapping = TextWrapping.Wrap;             tb.FontSize = 24.667;             tb.Text = "This is a basic ContentControl so put anything you want in here.";

            b.Child = tb;

            f.Content = b;

            f.Placement = (PlacementMode)Enum.Parse(typeof(PlacementMode), positioning.SelectionBoxItem.ToString());             f.PlacementTarget = sender as UIElement;                         f.IsOpen = true;

            f.Closed += delegate { LayoutRoot.Children.Remove(f.HostPopup); };

            ObjectTracker.Track(f);         }

-------- Original-Nachricht -------- Datum: Sat, 15 Sep 2012 09:07:11 -0700 Von: Tim Heuer notifications@github.com An: timheuer/callisto callisto@noreply.github.com CC: lukasf lukas.fellechner@gmx.net Betreff: Re: [callisto] Flyout placement is wrong if HostPopup's parent is set. (#82)

Can you provide me with a repro project showing the issue? The test app has one that roots it to the frame root and it works fine...so I want to make sure I understand the fix. Thanks for this though!

           —
           Reply to this email directly or view it on GitHub.         
timheuer commented 12 years ago

Got it. I'll make this change, but I'm also adding a change that doesn't make it totally necessary to add the HostPopup to the visual tree (if only doing so to get the keyboard scrollintoview functionality).