代码之家  ›  专栏  ›  技术社区  ›  aherrick

Xamarin Forms 3.1 UWP DisplayActionSheet-参数不正确。放置目标需要在可视树中

  •  0
  • aherrick  · 技术社区  · 8 年前

    我把我的Xamarin表单项目升级为表单3.1

    在UWP,我在下面的静态类中显示动作表:

    App.Current.MainPage.DisplayActionSheet();
    

    表2.5显示了没有问题的行动表。

    表3.1碰撞。

    ArgumentException: The parameter is incorrect.
    
    Placement target needs to be in the visual tree.
    

    有什么改变吗 DisplayActionSheet 在类文件中工作?

    我没有提到 ContentPage 在这一点上。

    有没有更好的方法 显示操作表 没有提及 内容页 是吗?

    请看这里: https://github.com/aherrick/UWPDisplayActionSheet

    1 回复  |  直到 8 年前
        1
  •  1
  •   Nico Zhu    8 年前

    很抱歉我之前的回答不正确

    问题是 Page1 是 ModalPage ,但您仍然使用 NavigationStack 作为父原因 ActionSheet 在错误的地方渲染。

    public static Page Instance
    {
        get
        {
            Page ret = null;
            if (Application.Current.MainPage.Navigation.NavigationStack != null)
                ret = Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
    
            if (ret == null)
                ret = Application.Current.MainPage;
    
            return ret;
        }
    }
    

    如果你用过 PushModalAsync 方法,页将堆叠在其中。 ModalStack

    get
    {
        Page ret = null;
        if (Application.Current.MainPage.Navigation.ModalStack != null)
            ret = Application.Current.MainPage.Navigation.ModalStack.LastOrDefault();
    
        if (ret == null)
            ret = Application.Current.MainPage;
    
        return ret;
    }