当我在android调试版中构建xamarin.forms应用程序时,我看到了汉堡菜单项,但是在发布模式下构建时,它们就会消失。这是专门在android项目中发生的,即使用masterdetailpages,并且发生在母版页中。任何帮助将不胜感激。以下是母版页代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="myApp.ViewAndViewModels.BookMasterDetailPageMaster"
xmlns:local="clr-namespace:myApp.ViewAndViewModels;assembly=myApp"
Title="☰" BackgroundColor="#91D8F7">
<StackLayout>
<ListView x:Name="MenuItemsListView"
SeparatorVisibility="None"
HasUnevenRows="true"
ItemsSource="{Binding MenuItems}">
<ListView.Header>
<StackLayout BackgroundColor="#91D8F7">
<Image x:Name="AppImage" BackgroundColor="#91D8F7"></Image>
<Label Text="Menu" HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand" FontSize="31">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Alvi Nastaleeq" />
<On Platform="Android" Value="Alvi Nastaleeq.ttf#Alvi Nastaleeq" />
<On Platform="UWP">/Assets/Fonts/Alvi Nastaleeq.ttf#Alvi Nastaleeq</On>
</OnPlatform>
</Label.FontFamily>
</Label>
</StackLayout>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid Grid.Row="1" ColumnSpacing="0" >
<StackLayout Grid.Row="1"
Orientation="Horizontal"
Spacing="0"
Margin="0,0">
<Image Source="{Binding IconImageSrc}" WidthRequest="32" HeightRequest="32"></Image>
<Label Text="{Binding Title}" HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand" FontSize="30">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Alvi Nastaleeq" />
<On Platform="Android" Value="Alvi Nastaleeq.ttf#Alvi Nastaleeq" />
<On Platform="UWP">/Assets/Fonts/Alvi Nastaleeq.ttf#Alvi Nastaleeq</On>
</OnPlatform>
</Label.FontFamily>
</Label>
</StackLayout>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BookMasterDetailPageMaster : ContentPage
{
public ListView ListView;
public BookMasterDetailPageMaster()
{
InitializeComponent();
AppImage.Source = ImageSource.FromResource("myApp.Assets.MainMenuIcon.png");
BindingContext = new BookMasterDetailPageMasterViewModel();
ListView = MenuItemsListView;
}
class BookMasterDetailPageMasterViewModel : INotifyPropertyChanged
{
public ObservableCollection<BookMasterDetailPageMenuItem> MenuItems { get; set; }
public ImageSource IconImageSource { get; set; }
public BookMasterDetailPageMasterViewModel()
{
IconImageSource = ImageSource.FromResource("myApp.Assets.Icons.articon.png");
MenuItems = new ObservableCollection<BookMasterDetailPageMenuItem>(new[]
{
new BookMasterDetailPageMenuItem { Id = 1, Title = "Menu1",IconImageSrc = this.IconImageSource,TargetType = typeof(Menu1) },
new BookMasterDetailPageMenuItem { Id = 2, Title = "Menu2", IconImageSrc = this.IconImageSource },
new BookMasterDetailPageMenuItem { Id = 3, Title = "Menu3", IconImageSrc = this.IconImageSource },
new BookMasterDetailPageMenuItem { Id = 4, Title = "Menu4", IconImageSrc = this.IconImageSource },
});
}
#region INotifyPropertyChanged Implementation
public event PropertyChangedEventHandler PropertyChanged;
async void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged == null)
return;
//PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
我只是在回答,因为我还无法发表评论,因此您可以将其视为评论
如果您无法共享代码,则需要提供更多信息,代码段或示例。
我设法解决了这个问题。在我的特定情况下,我在发行版的xamarin android项目中使用Dotfuscator,并且一旦禁用此功能,菜单项便开始显示。