xamarin.forms - TitleView 不显示
问题描述
我有一个支持 UWP 的 Xamarin.Forms 应用程序。在所有页面上,我都添加了一个带有标签的 TitleView:
var page = (Page)Activator.CreateInstance(item.TargetType);
Label titleViewLabel = new Label
{
Text = item.Title,
FontAttributes = FontAttributes.Bold,
FontSize = 25,
TextColor = Color.White,
BackgroundColor = backgroundColor,
Margin = 10
};
NavigationPage.SetTitleView(page, titleViewLabel);
现在我的一个页面有一个很好的标题“产品”。
这个页面有一个产品的 ListView,点击其中的任何项目,我们导航到 ProductDetailPage:
private async void ProductView_OnItemSelected(object sender, SelectedItemChangedEventArgs args)
{
Product product = (Product)args.SelectedItem;
ProductDetailPage productDetailPage = new ProductDetailPage
{
BindingContext = product,
Title = product.Name
};
await Navigation.PushAsync(productDetailPage);
}
当我们将标题设置为产品名称时,之前的标题“产品”被替换为特定的产品名称。没关系,但是当我按下按钮返回再次导航到产品页面时。但标题保持为空。我调试了它,并且可以看到 TitleView 仍然包含文本“Products”:
protected override void OnAppearing()
{
base.OnAppearing();
Label titleView = ((Label)NavigationPage.GetTitleView(this));
// titleView.Text has "Products!!
}
如何让标题显示?
解决方案
推荐阅读
- ios - 标题视图模型
- javascript - typeorm find with and & or where block
- node.js - 带有 Express-Messages 的 Express-Validator
- javascript - 使用正则表达式后如何不将大写转换为小写?
- c - 如何使用fork在C中的procecces之间发送信息
- python - pyinstaller 工作但 .exe 应用程序没有启动
- java - 我无法在 Vaadin 中将 int 转换为字符串
- kotlin - 我可以使用序列/集合 API 在 kotlin 中对 InputStream 进行分块吗?
- html - 为什么有这么多