我对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;
}
答案 0 :(得分:2)
如果要在第二页中更改后退按钮的标题(位于导航栏左侧),则应以第一页作为参数调用方法SetBackButtonTitle。因此,请将NavigationPage.SetBackButtonTitle(navigation,"Test");
修改为NavigationPage.SetBackButtonTitle(content,"Test");
答案 1 :(得分:0)
对于使用Xamarin.Forms WPF的用户,如果要更改后退按钮标题,可以执行以下操作:
final IFrameElement _iframeElement = IFrameElement();
_iframeElement.src = "https://index.hu/";
_iframeElement.style.border = 'none';
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
'iframeElement',
(int viewId) => _iframeElement,
);
Widget _iframeWidget;
_iframeWidget = HtmlElementView(
key: UniqueKey(),
viewType: 'iframeElement',
);
return Stack(
children: <Widget>[
IgnorePointer(
ignoring: true,
child: Center(
child: _iframeWidget,
),
),
Container(
color: Colors.transparent,
),
],
);