2018年6月23日土曜日

開発環境

Head First C# ―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Greene (著)、佐藤 嘉一 (監修, 監修)、木下 哲也 (翻訳)、オライリージャパン)の2章(あくまでコードである - 内部では)、エクササイズ(p. 76)を取り組んでみる。

コード

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:App1"
             x:Class="App1.MainPage">
    <StackLayout>
        <!-- Place new controls here -->
        <!--
     <Label Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
        -->
        <Button Text="スタート!"
                HorizontalOptions="Center"
                VerticalOptions="CenterAndExpand"
                Clicked="Button_ClickedAsync"/>
    </StackLayout>

</ContentPage>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace App1
{
 public partial class MainPage : ContentPage
 {
  public MainPage()
  {
   InitializeComponent();
  }

        private async void Button_ClickedAsync(object sender, EventArgs e)
        {
            while (IsVisible)
            {
                for (int c = 0; c < 253 && IsVisible; c++)
                {
                    this.BackgroundColor = Color.FromRgb(c, 255 - c, c);
                    await Task.Delay(3);
                }
                for (int c = 254; c > 0 && IsVisible; c--)
                {
                    this.BackgroundColor = Color.FromRgb(c, 255 - c, c);
                    await Task.Delay(3);
                }
            }
        }
    }
}

0 コメント:

コメントを投稿