【问题标题】:Getting Actual Placement of a Flyout获取 Flyout 的实际位置
【发布时间】:2016-10-19 00:09:49
【问题描述】:

当触发特定用户输入时,我有一个浮出控件出现在光标附近。

根据the docsFlyout.Placement 属性只是一个偏好,并不一定反映浮出控件的位置。

我希望框架调用GetFlyoutPlacement 来确定实际位置。我想知道实际的位置是什么,以便我可以添加一个指向光标位置的小箭头,如下所示:

我唯一的选择是自己拨打GetFlyoutPlacement(在Flyout.Opening 事件上触发),还是有更方便的方法?

【问题讨论】:

    标签: xaml windows-runtime


    【解决方案1】:

    我对@9​​87654322@ 和GetFlyoutPlacementTargetInfo 的调用导致Error HRESULT E_FAIL has been returned from a call to a COM component. 并没有让我继续下去,所以我最终实现了我想象的这些函数背后的逻辑:

    public static FlyoutPlacementMode GetActualFlyoutPlacement(
        Rect placementTarget,
        Size flyoutSize,
        FlyoutPlacementMode preferredPlacement )
    {
        Rect ViewArea = Window.Current.Bounds;
        ViewArea.X = 0; // may have non-zero offset for multi-monitor setups
        ViewArea.Y = 0; // but we are only interested in offset relative to app view area
    
        switch (preferredPlacement)
        {
            case FlyoutPlacementMode.Right:
                if (desiredSize.Width < ViewArea.Width - placementTarget.Right) return FlyoutPlacementMode.Right;
                if (desiredSize.Width < placementTarget.Left) return FlyoutPlacementMode.Left;
                if (desiredSize.Height < placementTarget.Top) return FlyoutPlacementMode.Top;
                return FlyoutPlacementMode.Bottom;
            case FlyoutPlacementMode.Left:
                ...
        }
    }
    

    【讨论】:

      【解决方案2】:

      查看我建议的方法here。我相信它更好,因为它只是比较浮出控件和目标元素的绝对坐标,而不是猜测内部放置算法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-27
        • 1970-01-01
        相关资源
        最近更新 更多