Hello, Windows IoT!
Hello, Worldなんて簡単!
プロジェクトの準備ができたところで、恒例の「Hello, World!」と参りましょう!
…と力む必要もなく、UWPのアプリはそのままRaspberry Piで動きます。 というわけで、「Hello, Windows IoT!」と表示し、「OK」ボタンを押すと終了するアプリが、こちら↓。
MainPage.xaml
<Page x:Class="Test.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" VerticalAlignment="Center"> <TextBlock Text="Hello, Windows IoT!" HorizontalAlignment="Center" FontSize="18" /> <Button Content="OK" Margin="10" Width="70" HorizontalAlignment="Center" Click="Button_Click"/> </StackPanel> </Page>
MainPage.xaml.cs
using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace Test { public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } //「OK」ボタンのClickイベントのイベントハンドラー private void Button_Click(object sender, RoutedEventArgs e) { // アプリを終了する App.Current.Exit(); } } }
プロジェクトを作ったときのテンプレートを、少々書き直しただけです!
ビルド!
Visual Studioの「ビルド」メニュー→「ソリューションのビルド」または「<プロジェクト名>のビルド」を選び、ビルドします。
エラーがなければ、「ビルド」メニュー→「ソリューションの配置」または「<プロジェクト名>の配置」を選び、アプリをRaspberry Piに配置します。
いざ!実行!
配置すると、アプリがRaspberry Piに書き込まれます。
「Device Portal」の「Apps」→「Apps Manager」の「Apps」一覧に、配置したアプリが表示されます。
右にある「Actions」ドロップダウンから「Start」を選べば、ほら!実行できました!
(リモートクライアントでの表示の例)
簡単でしょ?