【问题标题】:Set Back Button Title on Xamarin Forms C#在 Xamarin 窗体 C# 上设置后退按钮标题
【发布时间】:2017-12-25 16:08:09
【问题描述】:

我对 c# 和 Xamarin 很陌生,我刚刚遇到了一个问题。我似乎无法在导航页面上设置后退按钮标题。我尝试使用静态 SetBackButtonTitle 方法,但似乎没有将后退按钮设置为我想要的标题 “测试”,但它给了我“默认”标题,即“返回”。

        // The root page of your application
        var content = new ContentPage();


        var CompanyName = new Label();
        CompanyName.HorizontalTextAlignment = TextAlignment.Center;
        CompanyName.Text = "Test";

        var NextPage = new Button();
        NextPage.Text = "Next Page";
        NextPage.Font = Font.SystemFontOfSize(NamedSize.Large);
        NextPage.BorderWidth = 1;
        NextPage.HorizontalOptions = LayoutOptions.Center;
        NextPage.VerticalOptions = LayoutOptions.CenterAndExpand;

        var layout = new StackLayout();
        layout.VerticalOptions = LayoutOptions.CenterAndExpand;
        layout.Children.Add(CompanyName);
        layout.Children.Add(NextPage);

        content.Content = layout;

        var content2 = new ContentPage();

        var navigation = new NavigationPage(content);
        NavigationPage.SetHasBackButton(navigation,true);
        NavigationPage.SetBackButtonTitle(navigation,"Test");

        NextPage.Clicked += NextPageClicked;
        async  void NextPageClicked(object sender, EventArgs e)
        {
            await navigation.PushAsync(content2);
        }

        MainPage = navigation;



    }

【问题讨论】:

    标签: c# xamarin xamarin.ios


    【解决方案1】:

    如果你想改变第二页的返回按钮的标题(在导航栏的左边),你应该调用SetBackButtonTitle方法,以第一页为参数。所以请将NavigationPage.SetBackButtonTitle(navigation,"Test");修改为NavigationPage.SetBackButtonTitle(content,"Test");

    【讨论】:

      【解决方案2】:

      对于使用 Xamarin.Forms WPF 的用户,如果您想更改后退按钮标题,您可以这样做:

      protected override void OnDisappearing()
          {
              base.OnDisappearing();
      
              Title = "";
          }
      
      protected override void OnAppearing()
          {
              base.OnAppearing();
      
              Title = "MyTitle";
          }
      

      【讨论】:

        猜你喜欢
        • 2020-11-23
        • 1970-01-01
        • 2015-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-15
        相关资源
        最近更新 更多