【解決方法】xamarin.forms.shell でモーダル ページと非モーダル ページの間を移動するにはどうすればよいですか?


私は Xamarin.Forms 私が新しいもののために簡単に考えたであろう要件を持つアプリケーション Shell しかし、後を絶たない問題を引き起こしています。

TabBar を使用して自由にナビゲートできる「トップレベル」のページがいくつかあります。

これらの最上位ページの 1 つに、TabBar の一部ではない子のチェーンがあります。 このチェーンは、モーダルである必要がある 1 つ以上の画面で終了します。 これらのモーダル画面から、「ホーム」画面にすぐに戻れるようにする必要があります。

リンクされた画像は、これをより明確に示しています。

そして最も重要なことは、遷移のたびにナビゲーション イベントとページ ライフサイクル イベントを取得できることです。 (古いプッシュ/ポップ ナビゲーションから切り替えた理由の 1 つは、iOS で子モーダル ページが閉じられたときに親ページでイベントが発生しないためです。)

を使用してこれを設定する方法を教えてください。 Xamarin.Forms.Shell?

https://www.dropbox.com/s/puq87x0f2l4lyn2/Navigation%20Requirements.png?dl=0[^]

私が試したこと:

次のコードはほとんど機能しますが、モーダル画面からホーム画面に戻ると、 Shell スタイルを失います。 トップレベルのナビゲーションは TabBar.

public partial class MyNavigation : Shell
{
	public MyNavigation()
	{
		Items.Add( new TabBar()
		{
			Items =
			{
				new ShellContent
				{
					ContentTemplate = new DataTemplate( typeof( HomeView ) ),
					Icon = ImageSource.FromResource( "Resources.Home.png" ),
					Route = "Home"
					},
				new ShellContent
				{
					ContentTemplate = new DataTemplate( typeof( SettingsView ) ),
					Icon = ImageSource.FromResource( "Resources.Settings.png" ),
					Route = "Settings" }
			}
		});
		Routing.RegisterRoute( "ChildScreenOne", typeof( ChildScreenOne ) );
		Routing.RegisterRoute( "ChildScreenTwo", typeof( ChildScreenTwo ) );
		Style = ControlStyles.Shell_BaseStyle;
	}
}

public class HomeView : ContentPage
{
	public HomeView()
	{
		Style = ControlStyles.ContentPage_BaseStyle;
		Title = "Home";
		Button _button = new Button { Text = "Goto Screen One" };
		Grid grid = new Grid()
		{
			RowDefinitions =
			{
				new RowDefinition { Height = GridLength.Star },
				new RowDefinition { Height = GridLength.Auto },
				new RowDefinition { Height = GridLength.Star }
			},
			ColumnDefinitions =
			{
				new ColumnDefinition { Width = GridLength.Star },
				new ColumnDefinition { Width = GridLength.Auto },
				new ColumnDefinition { Width = GridLength.Star }
			}
		};
		grid.Children.Add( _button, 1, 1 );
		_button.Clicked += _button_Clicked;
		Content = grid;
	}

	private async void _button_Clicked( Object sender, EventArgs e )
	{
		await Shell.Current.GoToAsync( "ChildScreenOne" );
	}
}

public class ChildScreenOne : ContentPage
{
	public ChildScreenOne()
	{
		Title = "Child Screen One";
		Style = ControlStyles.ContentPage_BaseStyle;
		Button _button = new Button { Text = "Goto Screen Two" };
		Grid grid = new Grid()
		{
			RowDefinitions =
			{
				new RowDefinition { Height = GridLength.Star },
				new RowDefinition { Height = GridLength.Auto },
				new RowDefinition { Height = GridLength.Star }
			},
			ColumnDefinitions =
			{
				new ColumnDefinition { Width = GridLength.Star },
				new ColumnDefinition { Width = GridLength.Auto },
				new ColumnDefinition { Width = GridLength.Star }
			}
		};
		grid.Children.Add( _button, 1, 1 );
		_button.Clicked += _button_Clicked;
		Content = grid;
	}

	private async void _button_Clicked( Object sender, EventArgs e )
	{
		await Shell.Current.GoToAsync( "ChildScreenTwo" );
	}
}

public class ChildScreenTwo : ContentPage
{
	public ChildScreenTwo()
	{
		Title = "Child Screen Two";
		Style = ControlStyles.ContentPage_BaseStyle;
		Button _button = new Button { Text = "Goto Home" };
		Grid grid = new Grid()
		{
			RowDefinitions =
			{
				new RowDefinition { Height = GridLength.Star },
				new RowDefinition { Height = GridLength.Auto },
				new RowDefinition { Height = GridLength.Star }
			},
			ColumnDefinitions =
			{
				new ColumnDefinition { Width = GridLength.Star },
				new ColumnDefinition { Width = GridLength.Auto },
				new ColumnDefinition { Width = GridLength.Star }
			}
		};
		grid.Children.Add( _button, 1, 1 );
		_button.Clicked += _button_Clicked;
		Content = grid;
		Shell.SetPresentationMode( this, PresentationMode.ModalAnimated );
	}

	private async void _button_Clicked( Object sender, EventArgs e )
	{
		await Shell.Current.GoToAsync( @"\\Home" );
	}
}

解決策 1

素晴らしい。 答えはありません。 多分5年後誰も答えられない

コメント

タイトルとURLをコピーしました