C# (WinRT): ボタンのクリックと反応

ClickTestPage

xaml: ClickTestPage.xaml

<Page
    x:Class="Snippets.ClickTestPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Snippets"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid x:Name="grid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

    </Grid>
</Page>

C#: ClickTestPage.xaml.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;

namespace Snippets
{
    public sealed partial class ClickTestPage : Page
    {
        private Image image_;

        public ClickTestPage()
        {
            this.InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            StackPanel stackPanel = new StackPanel();
            this.grid.Children.Add(stackPanel);

            Image image = new Image();
            BitmapImage bitmapImage = new BitmapImage(new Uri("ms-appx:///Assets/Logo.png"));
            image.Source = bitmapImage;
            image.Stretch = Stretch.None;
            stackPanel.Children.Add(image);
            image_ = image;

            Button button = new Button();
            button.Content = "画像を非表示";
            button.Click += button_Click;
            stackPanel.Children.Add(button);
        }

        void button_Click(object sender, RoutedEventArgs e)
        {
            Button button = (Button)e.OriginalSource;
            if (image_.Visibility == Visibility.Visible)
            {
                image_.Visibility = Visibility.Collapsed;
                button.Content = "画像を表示";
            }
            else
            {
                image_.Visibility = Visibility.Visible;
                button.Content = "画像を非表示";
            }
        }
    }
}