【问题标题】:Switching ContentViews Xamarin.Forms切换 ContentViews Xamarin.Forms
【发布时间】:2018-04-02 06:51:16
【问题描述】:

我正在尝试创建自定义导航栏。我已经设置了我的导航栏并将其命名为NavBar,并在其上方添加了一个包含当前显示页面的 ContentView。我创建了一个包含 ContentView 的公共变量,如下所示:public ContentView CurrentPage = new Featured(); 并且我在页面中设置了一个 StackLayout,如下所示:

var stacklayout = new StackLayout { Spacing = 0 };
stacklayout.Children.Add(CurrentPage);
stacklayout.Children.Add(NavBar);
Content = stacklayout;

我有一个函数,当按下 NavBar 上的按钮以更改 CurrentPage 的值时调用,设置如下:

void NavToBuy(object sender, EventArgs e)
{
    CurrentPage = new Buy();
}

但是当按下按钮时,什么也没有发生。我认为该值正在更改,但未显示在屏幕上。有没有什么办法解决这一问题?提前感谢您的帮助:)

【问题讨论】:

    标签: c# xamarin xamarin.forms


    【解决方案1】:

    此答案来自 reddit 用户 brminnick1

    您需要在 StackLayout 中替换 CurrentPage,这将 看起来像这样:

    Device.BeginInvokeOnMainThread(() => stackLayout.Children[0] = new Buy());
    

    【讨论】:

      猜你喜欢
      • 2014-09-29
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      • 2021-07-31
      • 2020-05-21
      • 1970-01-01
      相关资源
      最近更新 更多