アプリ実行
Application.Propertiesを使用して、入力された名前を次のページに受け渡します。
Page1.xaml
BloodType.xaml
ソースコード
App.xaml
<Application xClass="HelloWorld.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlnsx="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Page1.xaml">
</Application>
Page1.xaml
<Page xClass="HelloWorld.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlnsx="http://schemas.microsoft.com/winfx/2006/xaml"
xmlnsmc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlnsd="http://schemas.microsoft.com/expression/blend/2008"
mcIgnorable="d"
dDesignHeight="300" dDesignWidth="300"
WindowTitle="あなたはの血液型は?">
<StackPanel>
<Label>あなたはの血液型は?</Label>
<TextBox Name="bloodTypeTextBox"></TextBox>
<TextBlock>
<Hyperlink
NavigateUri="BloodType.xaml"
RequestNavigate="Hyperlink_RequestNavigate">
送信
</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 {
public Page1() {
InitializeComponent();
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) {
Application.Current.Properties["BloodType"] = this.bloodTypeTextBox.Text;
}
}
}
BloodType.xaml
<Page xClass="HelloWorld.BloodType"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlnsx="http://schemas.microsoft.com/winfx/2006/xaml"
xmlnsmc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlnsd="http://schemas.microsoft.com/expression/blend/2008"
mcIgnorable="d"
dDesignHeight="300" dDesignWidth="300"
Loaded="Page_Loaded">
<StackPanel>
<TextBlock>あなたの血液型は、</TextBlock>
<Label Name="bloodTypeLabel"></Label>
<TextBlock>型ですね。</TextBlock>
</StackPanel>
</Page>
BloodType.xaml.cs
using System.Windows;
using System.Windows.Controls;
namespace HelloWorld {
public partial class BloodType : Page {
public BloodType() {
InitializeComponent();
}
private void Page_Loaded(object sender, RoutedEventArgs e) {
this.bloodTypeLabel.Content = Application.Current.Properties["BloodType"];
}
}
}