如何解决Xamarin Forms:更改页面时菜单消失
我遇到的问题是,当我在这些页面之间导航时,我的侧边菜单突然消失了。
我已经尝试了“任何事情”,我的意思是我已经尝试了所有我能做的事情,但结果还是一样。
This is the view before I navigate to SettingsPage
This is the view after I navigate to SettingsPage
如您所见,菜单消失了。
代码:
<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyTestApplication.Views"
xmlns:viewmodels="clr-namespace:MyTestApplication.viewmodels;assembly=MyTestApplication"
Title="MyTestApplication"
x:Class="MyTestApplication.AppShell">
<Shell.Resources>
<ResourceDictionary>
<Style x:Key="BaseStyle" targettype="Element">
<Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.ForegroundColor" Value="White" />
<Setter Property="Shell.TitleColor" Value="White" />
<Setter Property="Shell.disabledColor" Value="#B4FFFFFF" />
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.TabBarForegroundColor" Value="White"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
<Setter Property="Shell.TabBarTitleColor" Value="White"/>
</Style>
<Style targettype="TabBar" BasedOn="{StaticResource BaseStyle}" />
<Style targettype="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />
<Style targettype="local:SettingsPage" BasedOn="{StaticResource BaseStyle}" />
<Style Class="MenuItemLayoutStyle" targettype="Layout" ApplyToDerivedTypes="True">
<Setter Property="visualstatemanager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="normal">
<VisualState.Setters>
<Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource Primary}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</ResourceDictionary>
</Shell.Resources>
<Shell.FlyoutContentTemplate>
<DataTemplate>
<StackLayout>
<ListView x:Name="MenuItemsListView"
SeparatorVisibility="None"
HasUnevenRows="true"
ItemsSource="{Binding FlyoutItems}" ItemTapped="Settings_Button">
<ListView.Header>
<Grid BackgroundColor="Rosybrown">
<Grid.ColumnDeFinitions>
<ColumnDeFinition Width="10"/>
<ColumnDeFinition Width="*"/>
<ColumnDeFinition Width="10"/>
</Grid.ColumnDeFinitions>
<Grid.RowDeFinitions>
<RowDeFinition Height="30"/>
<RowDeFinition Height="80"/>
<RowDeFinition Height="Auto"/>
<RowDeFinition Height="10"/>
</Grid.RowDeFinitions>
<Label Grid.Row="2" Grid.Column="1"
TextColor="#d7d9b4"
Text="{Binding Title}"
FontSize="24"/>
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="15,10"
HorizontalOptions="FillAndExpand">
<Label VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
Text="{Binding Type}"
TextColor="Black"
FontSize="20"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView x:Name="MenuItemsListView2"
SeparatorVisibility="None"
HasUnevenRows="true"
ItemsSource="{Binding FlyoutItems2}" ItemTapped="Home_Button">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="15,10"
HorizontalOptions="FillAndExpand">
<Label VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
Text="{Binding Type}"
TextColor="Black"
FontSize="20"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</DataTemplate>
</Shell.FlyoutContentTemplate>
<FlyoutItem Title="Home" Icon="home.png">
<ShellContent Route="MainPage" ContentTemplate="{DataTemplate local:MainPage}"/>
</FlyoutItem>
<FlyoutItem Title="Settings" Icon="setting.png">
<ShellContent Route="SettingsPage" ContentTemplate="{DataTemplate local:SettingsPage}" />
</FlyoutItem>
<TabBar >
<ShellContent Route="LoginPage" ContentTemplate="{DataTemplate local:LoginPage}" />
</TabBar>
</Shell>
欢迎提出任何想法!
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。