【发布时间】:2022-01-04 08:34:01
【问题描述】:
我有代码可以使用 shell 视图的内容控制在所有页面上集成自定义标题栏。
这是我的代码:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SmartEntry.DashBoard">
Shell.TitleView = new Lable(Application.Current.Resources["TopBar"]);
<ContentPage.ToolbarItems>
<ToolbarItem Icon="logout_icon.png" Order="Primary" Priority="1" Clicked="ToolbarItem_Clicked"/>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout>
.....
这是我的 app.xaml 代码:
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new SmartEntry.LoginPage1());
var page = App.Current.MainPage.Navigation.NavigationStack.Last();
switch(page.ToString())
{
case "DashBoard.xaml":
lbltitle.Text = "DASHBOARD";
break;
case "GenerateBarcode.xaml":
lbltitle.Text = "WIFI SETTINGS";
break;
case "ManageDevice.xaml":
lbltitle.Text = "ADD DEVICE";
break;
case "MyProfile.xaml":
lbltitle.Text = "MY PROFILE";
break;
case "RegistrationUser.xaml":
lbltitle.Text = "MEMBER REGISTRATION";
break;
case "WifiSettings1.xaml":
lbltitle.Text = "WIFI SETTINGS";
break;
}
//MainPage = CrossConnectivity.Current.IsConnected ? (Page)new WifiSettings1() : new WifiSettings1();
}
这里是 app.xaml 标记:
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SmartEntry.App">
<Application.Resources>
<Label x:Name="lbltitle" TextColor="White" HorizontalOptions="Start" VerticalOptions="StartAndExpand" x:Key="TopBar"></Label>
</Application.Resources>
</Application>
在这里动态更改 lbltitle 控件的标题。但没有成功。
有没有人能解决我的问题。
【问题讨论】:
标签: xamarin xamarin.forms xamarin.android