Skip to content
Discussion options

You must be logged in to vote

Gotten some help from SO.

It seems I've been doing two things wrong:

  1. A single view instance cannot be reused to show multiple window instances
  2. IServiceProvider should be used to get the transient instance of the SubPage service

Fixing the two points above, MainPage now looks like this:

public partial class MainPage : ContentPage
{
	private readonly IServiceProvider services;

	public MainPage(IServiceProvider services)
	{
		InitializeComponent();
		this.services = services;
	}

	private void OnNewWindowClicked(object sender, EventArgs e)
	{
		Window newWindow = new()
		{
			Page = this.services.GetService<SubPage>(),
	 	};
		Application.Current?.OpenWindow(newWindow);
	}
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by symboli-rudolf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant