検証
項目 | 結果 |
---|---|
血液型入力ページがジャーナルから削除されていること | OK |
ソースコード
Human.cs
namespace HelloWorld { public class Human { public string BloodType { get; set; } } }
App.xaml
<Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="TopPage.xaml"> </Application>
TopPage.xaml
<Page x:Class="HelloWorld.TopPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Title="TopPage"> <TextBlock> あなたの <Hyperlink NavigateUri="Page1.xaml">血液型</Hyperlink> を表示します。 </TextBlock> </Page>
Page1.xaml
<Page x:Class="HelloWorld.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" WindowTitle="あなたはの血液型は?"> <StackPanel> <Label>あなたはの血液型は?</Label> <TextBox Name="bloodTypeTextBox"></TextBox> <TextBlock> <Hyperlink Click="Hyperlink_Click"> 送信 </Hyperlink> </TextBlock> </StackPanel> </Page>
Page1.xaml.cs
using System.Windows; using System.Windows.Controls; using System.Windows.Navigation; namespace HelloWorld { public partial class Page1 : Page { /// <summary> /// ナビゲーション完了後もアクセスできるようにキャッシュする。 /// </summary> NavigationService navigationService; public Page1() { InitializeComponent(); this.Loaded += (s, e) => { this.navigationService = this.NavigationService; this.navigationService.Navigated += _navigation_Navigated; }; } private void Hyperlink_Click(object sender, RoutedEventArgs e) { Human human = new Human() { BloodType = this.bloodTypeTextBox.Text }; BloodType page = new BloodType(human); this.NavigationService.Navigate(page); } private void _navigation_Navigated(object sender, NavigationEventArgs e) { // 2度目は入力ページをスキップする this.navigationService.RemoveBackEntry(); this.navigationService.Navigated -= _navigation_Navigated; this.navigationService = null; } } }
BloodType.xaml
<Page x:Class="HelloWorld.BloodType" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <StackPanel> <TextBlock>あなたの血液型は、</TextBlock> <Label Name="bloodTypeLabel"></Label> <TextBlock>型ですね。</TextBlock> </StackPanel> </Page>
BloodType.xaml.cs
using System.Windows.Controls; namespace HelloWorld { public partial class BloodType : Page { public BloodType(Human human) { InitializeComponent(); this.bloodTypeLabel.Content = human.BloodType; } } }
参考
NavigationService.RemoveBackEntry メソッド (System.Windows.Navigation)
"戻る" 履歴から最新の履歴項目を削除します。 ...