Я довольно новичок в разработке Android с C # и Xamarin. У меня проблема, я начинаю использовать MasterDetailPage, и теперь, когда я изменил XML для MasterDetailpage, у меня возникают очень трудные времена при компиляции программы для успешного запуска.
Мой код выглядит так:
XAML
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NavigationMasterDetail.MainPage">
<MasterDetailPage.Master>
<ContentPage Title="Menu">
<Grid BackgroundColor="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="200" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid>
<Image Source="bg.png" Aspect="AspectFill" />
<StackLayout Padding="0,20,0,0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
<Image BorderColor="White" Source="profile.png" Aspect="AspectFill" WidthRequest="85" HeightRequest="85" />
<Label Text="Adam Pedley" TextColor="White" FontSize="Large" />
</StackLayout>
</Grid>
<StackLayout Margin="20,20,20,0" Grid.Row="1" Spacing="15">
<ListView x:Name="navigationDrawerList" RowHeight="60" SeparatorVisibility="None" BackgroundColor="#e8e8e8" ItemSelected="OnMenuItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!-- Main design for our menu items -->
<StackLayout VerticalOptions="FillAndExpand" Orientation="Horizontal" Padding="20,10,0,10" Spacing="20">
<Image Source="{Binding Icon}" WidthRequest="40" HeightRequest="40" VerticalOptions="Center" />
<Label Text="{Binding Title}" FontSize="Medium" VerticalOptions="Center" TextColor="Black" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</Grid>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage></NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
Теперь код выглядит следующим образом:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using xfMasterDetailNavigation.MenuItems;
using xfMasterDetailNavigation.Views;
namespace xfMasterDetailNavigation
{
public partial class MainPage : MasterDetailPage
{
public List<MasterPageItem> menuList
{
get;
set;
}
public MainPage()
{
InitializeComponent();
menuList = new List<MasterPageItem>();
// Adding menu items to menuList and you can define title ,page and icon
menuList.Add(new MasterPageItem()
{
Title = "Home",
Icon = "homeicon.png",
TargetType = typeof(HelloTest)
});
menuList.Add(new MasterPageItem()
{
Title = "Contact",
Icon = "contacticon.png",
TargetType = typeof(Information)
});
menuList.Add(new MasterPageItem()
{
Title = "About",
Icon = "abouticon.png",
TargetType = typeof(AboutMe)
});
// Setting our list to be ItemSource for ListView in MainPage.xaml
navigationDrawerList.ItemsSource = menuList;
// Initial navigation, this can be used for our home page
Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(HelloTest)));
}
private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = (MasterPageItem)e.SelectedItem;
Type page = item.TargetType;
Detail = new NavigationPage((Page)Activator.CreateInstance(page));
IsPresented = false;
}
}
}
Теперь вот ошибки, которые я получаю:
1.) InitializeComponent() does not exist in current component
2.) navigationDrawerList does not exist in current component
3.) Property BorderColor was not found in type Image
Теперь я следовалпошаговое руководство отсюда https://www.c -sharpcorner.com / article / dynamic-master-detail-page-in-xamarin-forms /
Теперь Пожалуйста, я хочу знать, гдеЯ неправильно понимаю. Я новичок в этом