I work with an application made in Xamarin Forms that works on Android and IOS. I use a webview with a html and inside this html I call a javascript function when I login.
On Android it works fine but on IOS it doesn't work.
I read and apparently the error is due to the change from UIWebview to WKWebview, but so far I don't know how to fix this error.
I made my application on Windows in Visual Studio 2019, on the simulator device it works but on a physical device it doesn't work. In this case on Iphone not works.
This is my code:
LoginPage.xaml
<?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="MyLogin.Views.LoginPage">
<ContentPage.Content>
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="Sign In" FontAttributes="Bold" FontSize="Title" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="50" />
<Entry x:Name="emailEntry"
Grid.Row="2"
BackgroundColor="#31FFFFFF"
Placeholder="Email"
PlaceholderColor="#3AAAF4" />
<Entry x:Name="passwordEntry"
Grid.Row="3"
Margin="0,0,0,0"
BackgroundColor="#31FFFFFF"
IsPassword="True"
Placeholder="Password"
PlaceholderColor="#3AAAF4" />
<Button Text="Login" Clicked="OnLoginButtonClicked" BackgroundColor="#3AAAF4" TextColor="White" CornerRadius="8" />
<Label></Label>
<Label x:Name="messageLabel" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" WidthRequest="50" TextColor="Black" FontAttributes="Bold" />
<WebView x:Name="webView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" IsVisible="false" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
LoginPage.cs
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Plugin.DeviceInfo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Microsoft.CSharp;
using System.Net;
using System.IO;
using System.Reflection;
using Xamarin.Essentials;
using System.Web;
namespace MyLogin.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LoginPage : ContentPage
{
public string BlackboxString = "";
public LoginPage()
{
InitializeComponent();
webView.Source = LoadHTMLFileFromResource();
}
async void OnLoginButtonClicked(object sender, EventArgs e)
{
var blackbox = "";
blackbox = await webView.EvaluateJavaScriptAsync($"getBlackbox()");
//Code to login
}
private string GetLocalAddress()
{
var IpAddress = Dns.GetHostAddresses(Dns.GetHostName()).FirstOrDefault();
if (IpAddress != null)
return IpAddress.ToString();
return "Could not locate IP Address";
}
HtmlWebViewSource LoadHTMLFileFromResource()
{
var source = new HtmlWebViewSource();
// load HTML embed in PCL
var assembly = typeof(MainPage).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream("mypage.mypagename.html");
using (var reader = new StreamReader(stream))
{
source.Html = reader.ReadToEnd();
}
return source;
}
}
}
Please help me,
Thanks
Related
I've got a question for anyone who's worked with the ZXING barcode scanner in Xamarin.
I've got an app that has one page with the following code:
newitempage.xaml
Form Scanner
<?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="ERP.Views.NewItemPage"
Shell.PresentationMode="ModalAnimated"
Title="New Item"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="true">
<ContentPage.Content>
<StackLayout Spacing="3" Padding="15">
<Label Text="Text" FontSize="Medium" />
<Entry Text="{Binding Text, Mode=TwoWay}" FontSize="Medium" />
<Button Text="scan" Command="{Binding ScanCommand}" HorizontalOptions="FillAndExpand"></Button>
<Label Text="Description" FontSize="Medium" />
<Editor Text="{Binding Description, Mode=TwoWay}" x:Name="mycode" AutoSize="TextChanges" FontSize="Medium" Margin="0" />
<StackLayout Orientation="Horizontal">
<Button Text="Cancel" Command="{Binding CancelCommand}" HorizontalOptions="FillAndExpand"></Button>
<Button Text="Save" Command="{Binding SaveCommand}" HorizontalOptions="FillAndExpand"></Button>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
newitempage.xaml.cs
using ERP.Models;
using ERP.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using ZXing.Net.Mobile.Forms;
namespace ERP.Views
{
public partial class NewItemPage : ContentPage
{
public Item Item { get; set; }
public NewItemPage()
{
InitializeComponent();
BindingContext = new NewItemViewModel();
}
newitemviewmodel.cs
private async void OnScan()
{
var scan = new ZXingScannerPage();
await Navigation.PushAsync(scan);
scan.OnScanResult += (result) =>
{
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
mycode.Text = result.Text;
});
};
}
Please help how to solve my problem. Thanks
`await Navigation.PushAsync(scan);`
Navigation is a property of Page. You can't access it from the VM. A common pattern used in this scenario is to access the MainPage property of the App to use it's Navigation property
App.Current.MainPage.Navigation.PushAsync(scan);
I'm building a mobileApp with Xamarin forms. My problem is that I cannot get GroupHeader. I checked all platforms and websites. I couldn't find any solution for my problem. My fist listview works well and at second listview I want to show my values with groupheaders. My .xaml and .cs codes and scroonshots are below. I successfully got my all values from web service. And My values are shown at second listview except group headers.
<ListView x:Name="listview" HasUnevenRows="True" SeparatorVisibility="Default"
GroupDisplayBinding="{Binding Key}"
IsGroupingEnabled="True" ItemsSource="{Binding GroupedList}"
CachingStrategy="RecycleElement" Margin="0,0,0,15">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell Height="50" >
<Label Text ="{Binding Key}" Margin="0,20,0,0" FontSize="Medium" TextColor="Gray" />
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid BackgroundColor="White" Margin="0,0,0,1" >
<Grid.RowDefinitions>
<RowDefinition Height="0.4*"/>
<RowDefinition Height="0.6*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding PayDeskName}" Grid.Row="0" HorizontalOptions="Start" VerticalTextAlignment="Center" FontAttributes="Bold" TextColor="Gray"/>
<Label Grid.Column="0" Text="{Binding CollectionType}" Grid.Row="1" HorizontalOptions="Start" VerticalTextAlignment="Center" FontAttributes="Bold" TextColor="Blue"/>
<Label Grid.Column="1" Text="{Binding CollectionAmount, StringFormat='{0:N}'}" Grid.Row="1" HorizontalOptions="End" VerticalOptions="Center" FontSize="Large" TextColor="Blue"></Label>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
--
using MunIS.Parameters;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
namespace MunIS.AccrumentCollection
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CollectionPage : ContentPage
{
public CollectionPage()
{
InitializeComponent();
}
public PayDeskBaseCollectionParameters[] CollectionList { get; set; }
public ObservableCollection<Grouping<string, PayDeskBaseCollectionParameters>> GroupedList { get; set; }
public IEnumerable<IGrouping<string, PayDeskBaseCollectionParameters>> CollectionTypeBasedGroupedList { get; set; }
async void GetCollectionList(object sender, EventArgs e)
{
activityStackLayout.IsVisible = true;
activityIndicator.IsRunning = true;
loadingTxt.IsVisible = true;
string queryIntervalStartDate = dtIntervalStart.Date.ToString("MM.dd.yyyy");
string queryIntervalFinishDate = dtIntervalFinish.Date.ToString("MM.dd.yyyy");
CollectionDetailQueryCriteriaParameters criteria = new CollectionDetailQueryCriteriaParameters();
criteria.CollectionDateStart = dtIntervalStart.Date;
criteria.CollectionDateFinish = dtIntervalFinish.Date;
ServiceCaller serviceCaller = new ServiceCaller();
CollectionList = await serviceCaller.ListPayDeskBasedCollections(criteria);
var groupedCollectionList = CollectionList.GroupBy(c => c.CollectionType).Select(
g => new
{
CollectionType = g.Key,
CollectionAmount = g.Sum(s => s.CollectionAmount)
});
GroupedList = new ObservableCollection<Grouping<string, PayDeskBaseCollectionParameters>>(CollectionList.GroupBy(c => c.PayDeskName)
.Select(k => new Grouping<string, PayDeskBaseCollectionParameters>(k.Key + "\t\t" + CollectionList
.Where(c => c.PayDeskName == k.Key)
.Sum(x => x.CollectionAmount).ToString("N"), k)));
listview1.ItemsSource = groupedCollectionList;
listview.ItemsSource = GroupedList;
activityIndicator.IsRunning = false;
loadingTxt.IsVisible = false;
activityStackLayout.IsVisible = false;
}
}
}
And this is my Grouping.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace MunIS
{
public class Grouping<K, T> : ObservableCollection<T>
{
public K Key { get; set; }
public Grouping(K key, IEnumerable<T> items)
{
Key = key;
foreach (var item in items)
{
this.Items.Add(item);
}
}
}
}
See my Page I want to get groupheaders
I think you need to remove GroupDisplayBinding from your listview element.
<ListView x:Name="listview" HasUnevenRows="True" SeparatorVisibility="Default"
GroupDisplayBinding="{Binding Key}"
IsGroupingEnabled="True" ItemsSource="{Binding GroupedList}"
CachingStrategy="RecycleElement" Margin="0,0,0,15">
This property is mutually exclusive with GroupHeaderTemplate property.
Setting it will set GroupHeaderTemplate to null.
From the docs: https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.listview.groupdisplaybinding?view=xamarin-forms#remarks
This worked for me
remove the x:DataType attribute from the XAML. For some reason doing this for the overall page creates problems with templated controls that have their own context.
And as Jeroen Corteville said, you need to remove the GroupDisplayBinding aswell. The two do the same, but somehow works differently.
Please help me out. In order for you to understand my problem, I have replicated the scenario in sample application
As Xamarin.Forms introduced FlyoutPage page in 5.0 version, navigation is not working in one of the applications.
I am opening main page from app.xaml.cs like this await NavigationService.NavigateAsync("Page3");
FlyoutPage:
<FlyoutPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:PrismNavigation.Views;assembly=PrismNavigation"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PrismNavigation.Views.Page3"
Title="Master">
<FlyoutPage.Flyout>
<ContentPage Title="Menu">
<StackLayout>
<Button Text="Page2" HeightRequest="50" WidthRequest="100" Command="{Binding NavigateCommand}" CommandParameter="Page2"></Button>
</StackLayout>
</ContentPage>
</FlyoutPage.Flyout>
<FlyoutPage.Detail>
<NavigationPage>
<x:Arguments>
<views:Page1></views:Page1>
</x:Arguments>
</NavigationPage>
</FlyoutPage.Detail>
</FlyoutPage>
Page3ViewModel:
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PrismNavigation.ViewModels
{
public class Page3ViewModel : ViewModelBase
{
private readonly INavigationService navigationService;
public Page3ViewModel(
INavigationService navigationService)
: base(navigationService)
{
this.navigationService = navigationService;
this.NavigateCommand = new DelegateCommand<string>(this.NavigateCommandExecute);
}
public override void OnNavigatedTo(INavigationParameters parameters)
{
base.OnNavigatedTo(parameters);
}
private void NavigateCommandExecute(string obj)
{
this.navigationService.NavigateAsync($"NavigationPage/{obj}");
}
public DelegateCommand<string> NavigateCommand { get; set; }
}
}
App:
using Prism;
using Prism.Ioc;
using PrismNavigation.ViewModels;
using PrismNavigation.Views;
using Xamarin.Essentials.Implementation;
using Xamarin.Essentials.Interfaces;
using Xamarin.Forms;
namespace PrismNavigation
{
public partial class App
{
public App(IPlatformInitializer initializer)
: base(initializer)
{
}
protected override async void OnInitialized()
{
InitializeComponent();
await NavigationService.NavigateAsync("Page3");
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<IAppInfo, AppInfoImplementation>();
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<Page1>();
containerRegistry.RegisterForNavigation<Page2>();
containerRegistry.RegisterForNavigation<Page3, Page3ViewModel>();
}
}
}
When I am trying to navigate to Page2 from menu, i can not do that. When I click the button, navigate command is executed, but navigation is not happening.
Update:
In addition to my old answer, which you have fixed in the question, it seems that the FlyoutPage is not supported by Prism 8 according to this. It is planned for 8.1. So, you can either wait 8.1 or replace it with MasterDetailPage. I tried your example with MasterDetailPage and it worked fine for me:
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PrismNavigation.Views.Page3">
<MasterDetailPage.Master>
<ContentPage Title="Menu">
<StackLayout Padding="20">
<Button Text="Page2" HeightRequest="50" WidthRequest="100" Command="{Binding NavigateCommand}" CommandParameter="Page2"></Button>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<ContentPage Title="This is Page1"></ContentPage>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
Old answer:
Seems like you didn't pass any parameter to your NavigateCommand. Try this
<StackLayout>
<Button Text="Page2" HeightRequest="50" WidthRequest="100" Command="{Binding NavigateCommand}" CommandParameter="Page2"></Button>
</StackLayout>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Just check the image below. I want to change the color of marked areas on the Image. The image is a screenshot of UWP application developed using xamarin forms cross platform project (PCL).
I am using MasterDetail page navigation.
Now Color is changed as per my first requirement.
Now what I want is a screen design like below
Now I am getting a result as below
Result of second screen ie, after navigating to stock entry page
Source Code
1. MasterDetailsPage.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="GST.Views.MasterDetailsPage"
Title="Stock Manager"
MasterBehavior="SplitOnPortrait"
BackgroundColor="#0063b1"
xmlns:pages="clr-namespace:GST.Views;assembly=GST">
<MasterDetailPage.Master >
<pages:MasterDetailsPageMaster x:Name="MasterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage >
<x:Arguments>
<pages:GST_Home />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
2. MasterDetailsPage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MasterDetailsPage : MasterDetailPage
{
public MasterDetailsPage()
{
InitializeComponent();
MasterPage.ListView.ItemSelected += ListView_ItemSelected;
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MasterDetailsPageMenuItem;
if (item == null)
return;
var page = (Page)Activator.CreateInstance(item.TargetType);
Detail.Title = item.Title;
IsPresented = false;
Detail.Navigation.PushAsync(page);
MasterPage.ListView.SelectedItem = null;
}
}
}
3. MasterDetailsPageDetail.xaml
<?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="GST.Views.MasterDetailsPageDetail"
BackgroundColor="{StaticResource Key=background-color}"
Title="Master GST Title Detailed" >
<StackLayout Padding="10">
<Label Text="This is a detail page. To get the 'triple' line icon on each platform add a icon to each platform and update the 'Master' page with an Icon that references it."/>
</StackLayout>
</ContentPage>
4.MasterDetailsPageDetail.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MasterDetailsPageDetail : ContentPage
{
public MasterDetailsPageDetail()
{
InitializeComponent();
// NavigationPage.SetHasBackButton(this, false);
// NavigationPage.SetHasNavigationBar(this, false);
}
}
}
5. MasterDetailsPageMaster.xaml
<?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="GST.Views.MasterDetailsPageMaster"
Title="Home">
<StackLayout>
<ListView x:Name="ListViewMenuItems"
SeparatorVisibility="None"
HasUnevenRows="true"
ItemsSource="{Binding MenuItems}">
<ListView.Header>
<Grid BackgroundColor="#03A9F4">
<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.Column="1"
Grid.Row="2"
Text="AppName"
Style="{DynamicResource SubtitleStyle}"/>
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="15,10" HorizontalOptions="FillAndExpand">
<Label VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
Text="{Binding Title}"
FontSize="24"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
6.MasterDetailsPageMaster.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MasterDetailsPageMaster : ContentPage
{
public ListView ListView => ListViewMenuItems;
public MasterDetailsPageMaster()
{
InitializeComponent();
BindingContext = new ViewModels.MasterDetailsPageMasterViewModel();
}
}
}
7.MasterDetailsPageMenuItem.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GST.Views
{
public class MasterDetailsPageMenuItem
{
public MasterDetailsPageMenuItem()
{
TargetType = typeof(MasterDetailsPageDetail);
}
public int Id { get; set; }
public string Title { get; set; }
public Type TargetType { get; set; }
}
}
8.GST_Home.xaml -- Home Dash
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
NavigationPage.HasNavigationBar="False"
Title="Home Dash"
x:Class="GST.Views.GST_Home">
<StackLayout Padding="10">
<Label Text="This is a detail page. To get the 'triple' line icon on each platform add a icon to each platform and update the 'Master' page with an Icon that references it."/>
</StackLayout>
</ContentPage>
9.GST_Home.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class GST_Home : ContentPage
{
public GST_Home()
{
InitializeComponent();
}
}
}
If you want full source code please refer my code which is uploaded on Google Drive: https://drive.google.com/file/d/0B2XtD2dQvEhzb1NnNGdydG91S0k/view?usp=sharing
If you wish to maintain the color of Title bar through out the app then you can write the following code inside the OnLaunched in the App.xaml.cs within Xamarin.UWP client project. For more please refer to Customizing Title Bar and Status Bar in Universal Windows Platform (UWP).
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
{
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
if (titleBar != null)
{
titleBar.ButtonBackgroundColor = Colors.Red;
titleBar.ButtonForegroundColor = Colors.White;
titleBar.BackgroundColor = Colors.Red;
titleBar.ForegroundColor = Colors.White;
}
}
And if you want to custom tool bar background color, you could set the BarBackgroundColor of the NavigationPage. You can do something like the following code.
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
......
var nav = new NavigationPage();
nav.PushAsync(page);
nav.BarBackgroundColor = Color.MediumPurple;
Detail = nav;
}
I'm having trouble setting the rootpage of my Application. I wasn't able to show the right page. The first Mainpage is the default from the start and the second MainPage there is the name of the page that I created. Here's my code.
App.cs
public App()
{
MainPage = new NavigationPage(new MainPage());
}
And here is the code of my the page that i want to set as root page.
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:XamarinDemoApp"
x:Class="XamarinDemoApp.MainPage"
xmlns:ViewModels="clr-namespace:XamarinDemoApp.ViewModels;assembly=XamarinDemoApp">
<ContentPage.BindingContext>
<ViewModels:MainViewModel />
</ContentPage.BindingContext>
<ListView ItemsSource="{Binding EmployeesList}"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Name}"
FontSize="24"/>
<Label Text="{Binding Department}"
FontSize="18"
Opacity="0.6"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
This is the code behind my MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using XamarinDemoApp.ViewModels;
namespace XamarinDemoApp
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
}
}
This is the Stack Trace field I get.
[External Code]
> 0xC in XamarinDemoApp.MainPageMain.InitializeComponent at c:\Users\LIFEBOOK E743\Documents\Visual Studio 2013\Projects\XamarinDemoApp\XamarinDemoApp\obj\Debug\XamarinDemoApp.Views.MainPageMain.xaml.g.cs:21,13 C#
0x9 in XamarinDemoApp.MainPageMain..ctor at c:\Users\LIFEBOOK E743\Documents\Visual Studio 2013\Projects\XamarinDemoApp\XamarinDemoApp\Views\MainPageMain.xaml.cs:16,13 C#
0x9 in XamarinDemoApp.App..ctor at c:\Users\LIFEBOOK E743\Documents\Visual Studio 2013\Projects\XamarinDemoApp\XamarinDemoApp\App.cs:14,12 C#
0x12 in XamarinDemoApp.Droid.MainActivity.OnCreate at c:\Users\LIFEBOOK E743\Documents\Visual Studio 2013\Projects\XamarinDemoApp\XamarinDemoApp.Droid\MainActivity.cs:20,13 C#
0x13 in Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ at /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:2857,4 C#
This is in the wrong place ...
NavigationPage.SetHasNavigationBar(this, false);
It should be
public App()
{
var mainPage = new NavigationPage(new MainPage());
NavigationPage.SetHasNavigationBar(this, false);
MainPage = mainPage;
}