Skip to content

13 Xamarin UI

Xamarin UI

Xamarin.Forms provides a number of different page navigation experiences, depending upon the Page type being used.

native

NavigationPage

Starting up

  • MainPage = new NavigationPage(new Page1Xaml());

Pushing

  • await Navigation.PushAsync(new Page2Xaml());

Poping

  • await Navigation.PopAsync();

Pop to start

  • await Navigation.PopToRootAsync();

native native native

Data in navigation

Passing data to next page

  • Via constructor
  • Via BindingContext

Receive data back - callbacks

In page B:

1
2
public event EventHandler LoginSucceeded;
LoginSucceeded(this, EventArgs.Empty);

In page A:

1
2
BPage.LoginSucceeded += HandleLoginSucceeded;
private async void HandleLoginSucceeded(object sender, EventArgs e)

Manipulate stack

1
Navigation.InsertPageBefore (new MainPage(), this);

native native

Database - EF Core

EF Core

EF Core is now possible out of box!

  • Microsoft.EntityFrameworkCore.Sqlite

In dbcontext constructor call

1
2
3
// initiate sqlite on ios
SQLitePCL.Batteries_V2.Init(); 
this.Database.EnsureCreated();

In OnConfiguring figure out path for sqlite file

1
2
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "appdb.db3");
optionsBuilder.UseSqlite($"Filename={dbPath}");

EF Core - ios

Entity Framework Core uses reflection to invoke functions which the Xamarin.iOS linker may strip out while in Release mode configurations.

Two possible ways how to solve:

  • add --linkskip System.Core to the Additional mtouch arguments in the iOS Build options
  • set the Xamarin.iOS Linker behavior to Don't Link in the iOS Build options