简体   繁体   中英

Xamarin Forms Pop Out Navigation Empty on iOS

I have made a cross platform app with Xamarin Forms that relies on a pop out style navigation menu (Navigation Master Detail page) to switch between views.

On iOS simulators the navigation behaves as intended; however on physical devices the navigation menu is empty.

I have tested several version of iOS to rule out compatibility issues, and I've confirmed the UI elements are loading correctly - this has confirmed the list data is not loading.

Here is my Navigation Master code behind:

public partial class NavigationMaster : ContentPage
{
    public ListView ListView;

    public NavigationMaster()
    {
        Icon = Services.PlatformImage.Resolver("menu.png");
        InitializeComponent();

        BindingContext = new NavigationMasterViewModel();
        ListView = MenuItemsListView;
    }

    class NavigationMasterViewModel : INotifyPropertyChanged
    {

        private ObservableCollection<NavigationMenuItem> _menuItems = new ObservableCollection<NavigationMenuItem>();
        public ObservableCollection<NavigationMenuItem> MenuItems
        {
            get { return _menuItems; }
            set
            {
                _menuItems = value;
                OnPropertyChanged(nameof(MenuItems));
            }
        }

        public NavigationMasterViewModel()
        {
            MenuItems = new ObservableCollection<NavigationMenuItem>(new[]
            {
                new NavigationMenuItem { Id = 1, Title = "Projects", TargetType = typeof(Views.Projects)},
                new NavigationMenuItem { Id = 2, Title = "Tickets", TargetType = typeof(Views.Tickets)},
                new NavigationMenuItem { Id = 3, Title = "Documents", TargetType = typeof(Views.Documents)},
                new NavigationMenuItem { Id = 4, Title = "Calendar", TargetType = typeof(Views.Calendar)},
                new NavigationMenuItem { Id = 5, Title = "Discussion", TargetType = typeof(Views.Discussion)},
            });
        }
        #region INotifyPropertyChanged Implementation
        public event PropertyChangedEventHandler PropertyChanged;
        void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}

And my XAML:

<StackLayout>
    <ListView x:Name="MenuItemsListView"
              SeparatorVisibility="Default"
              HasUnevenRows="False"
              ItemsSource="{Binding MenuItems}"
              >
        <ListView.Header>
            <Grid BackgroundColor="#222222">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Image Source="Logo.png" Margin="40" Scale="0.5" HorizontalOptions="Center" VerticalOptions="Center" Grid.Row="1" Grid.Column="1"/>
            </Grid>
        </ListView.Header>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout HorizontalOptions="Start">
                        <Label Text="{Binding Title}"
                               TextColor="#000000"
                               VerticalOptions="Start"
                               VerticalTextAlignment="Center" 
                               FontSize="Small"
                               Margin="10"/>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>

Is the system version and model of iOS simulators different from your real device? Try to delete two folders "obj" and "bin" under your forms project,and rebuild it.

This was caused by the linker behaviour configuration - if linking is disabled the navigation list does not populate.

Setting the linker behavior to "Link Framework SDKs Only" resolved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM