/////////////////
// Window05_1.cs
//参照：https://learn.microsoft.com/ja-jp/dotnet/api/system.windows.controls.contentcontrol?view=windowsdesktop-8.0
// Window05_2.cs
//参照：https://learn.microsoft.com/ja-jp/dotnet/desktop/wpf/advanced/alignment-margins-and-padding-overview?view=netframeworkdesktop-4.8
// Window05_3.cs
//参照：https://learn.microsoft.com/ja-jp/dotnet/api/system.windows.controls.canvas?view=windowsdesktop-8.0
/////////////////
using System;
using System.Windows;
using System.Windows.Controls;			//コントロールを利用する為
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Imaging;		//BitmapFrameを使用する為

namespace Window05_1
{
	///////////////////////////
	//エントリーポイントクラス
	///////////////////////////
	class MainApp
	{
		[STAThread]
		public static void Main()
		{
			MainWindow mwnd = new MainWindow();
			Application ap = new Application();
			ap.Run(mwnd);
		}
	}

	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			/* ウィンドウスタイル、クライアントエリア色、アイコンとZオーダーの指定 */
			this.WindowStyle = WindowStyle.ThreeDBorderWindow;	//None、SingleBorderWindow（規定値）、ThreeDBorderWindowまたはToolWindow
			this.Background = SystemColors.WindowBrush;			//本例ではウインドウのクライアントエリア色にする
			this.Icon = BitmapFrame.Create(new Uri("Icon.ico", UriKind.Relative));	//同じフォールダーのIcon.icoを読んで使用する
			this.Topmost = false;								//最上位ウィンドウとするか否か
			/* 起動時の位置－上、左座標で指定または、起動時の位置で指定 */
			this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
			/* ウィンドウサイズ－幅、高さで指定または、コンテンツサイズに合わせる */
			this.Width = 640;
			this.Height = 480;
			//this.Content = "このウィンドウはWPFベースで、プロパティチェックの為に作られました。";
			//this.SizeToContent = SizeToContent.WidthAndHeight;	//Contentサイズに合わせる（Height、Manual、WidthまたはWidthAndHeight）
			this.ResizeMode = ResizeMode.CanResizeWithGrip;		//CanMinimize、CanResize、CanResizeWithGrip、NoResizeから選択
			this.ShowActivated = true;							//アクティブ状態で初期表示するかどうか（規定値 true）
			this.ShowInTaskbar = true;							//タスクバーにボタン表示するか否か
			this.Title = "Window05";
			InitControls();
		}

		/////////////////////////////////////////////
		// Microsoft Learnのサンプルを二つ一緒にする
		/////////////////////////////////////////////
		public void InitControls()
		{
			/* ---------- */
			/* Window05_1 */
			/* ---------- */
			/* 様々な様々なコンテンツの入ったボタン */
			//文字列をいれたボタン
			Button StrBtn = new Button();
			StrBtn.Height = 32;
			StrBtn.Width = 240;
			StrBtn.HorizontalContentAlignment = HorizontalAlignment.Left;
			StrBtn.VerticalContentAlignment = VerticalAlignment.Top;
			//StrBtn.HorizontalContentAlignment = HorizontalAlignment.Right;
			//StrBtn.VerticalContentAlignment = VerticalAlignment.Bottom;
			StrBtn.Content = "This is string content of a Button";
			//DateTimeオブジェクトを入れたボタン
			Button ObjBtn = new Button();
			ObjBtn.Height = 32;
			ObjBtn.Width = 180;
			ObjBtn.HorizontalAlignment = HorizontalAlignment.Right;
			ObjBtn.HorizontalContentAlignment = HorizontalAlignment.Right;
			ObjBtn.VerticalContentAlignment = VerticalAlignment.Bottom;
			//ObjBtn.HorizontalContentAlignment = HorizontalAlignment.Left;
			//ObjBtn.VerticalContentAlignment = VerticalAlignment.Top;
			DateTime dateTime1 = new DateTime(2004, 3, 4, 13, 6, 55);
			ObjBtn.Content = dateTime1;
			//単一UIElementを入れたボタン
			Button UIEBtn = new Button();
			UIEBtn.Height = 60;
			UIEBtn.Width = 60;
			UIEBtn.HorizontalAlignment = HorizontalAlignment.Center;
			UIEBtn.HorizontalContentAlignment = HorizontalAlignment.Left;
			UIEBtn.VerticalContentAlignment = VerticalAlignment.Bottom;
			//UIEBtn.HorizontalContentAlignment = HorizontalAlignment.Right;
			//UIEBtn.VerticalContentAlignment = VerticalAlignment.Top;
			Rectangle rec = new Rectangle();
			rec.Width = 40;
			rec.Height = 40;
			rec.Fill = Brushes.Blue;
			UIEBtn.Content = rec;
			//複数オブジェクトの入ったパネルを入れたボタン
			Button panelBtn = new Button();
			panelBtn.Height = 240;
			panelBtn.Width = 180;
			panelBtn.HorizontalAlignment = HorizontalAlignment.Right;
			panelBtn.HorizontalContentAlignment = HorizontalAlignment.Left;
			panelBtn.VerticalContentAlignment = VerticalAlignment.Top;
			//panelBtn.HorizontalContentAlignment = HorizontalAlignment.Right;
			//panelBtn.VerticalContentAlignment = VerticalAlignment.Bottom;
			StackPanel  StckPanel = new StackPanel();
			Ellipse ellipse = new Ellipse();
			TextBlock textBlock = new TextBlock();
			ellipse.Width = 40;
			ellipse.Height = 40;
			ellipse.Fill = Brushes.Blue;
			textBlock.TextAlignment = TextAlignment.Center;
			textBlock.Text = "Multiple Objs Button";
			StckPanel.Children.Add(ellipse);
			StckPanel.Children.Add(textBlock);
			panelBtn.Content = StckPanel;
			//コンテナ（スタックパネル、ドックパネル、キャンバス）に入れる
			StackPanel Container = new StackPanel();
			//DockPanel Container = new DockPanel();
			//Canvas Container = new Canvas();
			Container.HorizontalAlignment = HorizontalAlignment.Left;
			Container.VerticalAlignment = VerticalAlignment.Top;
			//Container.HorizontalAlignment = HorizontalAlignment.Right;
			//Container.VerticalAlignment = VerticalAlignment.Bottom;
			Container.Children.Add(StrBtn);
			Container.Children.Add(ObjBtn);
			Container.Children.Add(UIEBtn);
			Container.Children.Add(panelBtn);

			/* ---------- */
			/* Window05_2 */
			/* ---------- */
			//Borderを追加
			Border myBorder = new Border();
			myBorder.Background = Brushes.LightBlue;
			myBorder.BorderBrush = Brushes.Black;
			myBorder.Padding = new Thickness(15);
			myBorder.BorderThickness = new Thickness(2);
			//StackPanelを追加
			StackPanel myStackPanel = new StackPanel();
			myStackPanel.Background = Brushes.White;
			myStackPanel.HorizontalAlignment = HorizontalAlignment.Center;
			myStackPanel.VerticalAlignment = VerticalAlignment.Top;
			//TextBlockを追加
			TextBlock myTextBlock = new TextBlock();
			myTextBlock.Margin = new Thickness(5, 0, 5, 0);
			myTextBlock.FontSize = 12;
			myTextBlock.HorizontalAlignment = HorizontalAlignment.Center;
			myTextBlock.Text = "Alignment, Margin and Padding Sample";
			//Buttonを3つ追加
			Button myButton1 = new Button();
			myButton1.HorizontalAlignment = HorizontalAlignment.Left;
			myButton1.Margin = new Thickness(20);
			myButton1.Content = "My Button1";
			Button myButton2 = new Button();
			myButton2.HorizontalAlignment = HorizontalAlignment.Right;
			myButton2.Margin = new Thickness(10);
			myButton2.Content = "My Button 2";
			Button myButton3 = new Button();
			myButton3.HorizontalAlignment = HorizontalAlignment.Stretch;
			myButton3.Margin = new Thickness(0);
			myButton3.Content = "My Button 3";
			//StackPanelにコントロールを要素として追加
			myStackPanel.Children.Add(myTextBlock);
			myStackPanel.Children.Add(myButton1);
			myStackPanel.Children.Add(myButton2);
			myStackPanel.Children.Add(myButton3);
			//BorderにStackPanelを単独のコンテンツとして追加
			myBorder.Child = myStackPanel;

			/* ---------- */
			/* Window05_3 */
			/* ---------- */
			//親Canvasの作成
			Canvas ParentCvs = new Canvas();
			//ParentCvs.Width = 210;
			//ParentCvs.Height = 210;
			double unit = this.Width / (3 * 4);	//ウィンドウクライアントエリアの1/3を4等分する
			//子Canvasの作成
			Canvas ChildCvs1 = new Canvas();
			ChildCvs1.Background = Brushes.Red;
			ChildCvs1.Height = unit;
			ChildCvs1.Width = unit;
			Canvas.SetTop(ChildCvs1, unit * 0.5);
			Canvas.SetLeft(ChildCvs1, unit);
			Canvas ChildCvs2 = new Canvas();
			ChildCvs2.Background = Brushes.Green;
			ChildCvs2.Height = unit;
			ChildCvs2.Width = unit;
			Canvas.SetTop(ChildCvs2, unit);
			Canvas.SetLeft(ChildCvs2, unit * 1.5);
			Canvas ChildCvs3 = new Canvas();
			ChildCvs3.Background = Brushes.Blue;
			ChildCvs3.Height = unit;
			ChildCvs3.Width = unit;
			Canvas.SetTop(ChildCvs3, unit * 1.5);
			Canvas.SetLeft(ChildCvs3, unit * 2);
			//親へ子を追加する
			ParentCvs.Children.Add(ChildCvs1);
			ParentCvs.Children.Add(ChildCvs2);
			ParentCvs.Children.Add(ChildCvs3);

			//グリッド
			Grid gridContainer = new Grid();
			gridContainer.ColumnDefinitions.Add(new ColumnDefinition());
			gridContainer.ColumnDefinitions.Add(new ColumnDefinition());
			gridContainer.ColumnDefinitions.Add(new ColumnDefinition());
			//Containerをグリッドに追加
			Grid.SetColumn(Container, 0);
			gridContainer.Children.Add(Container);
			//myBorderをグリッドに追加
			Grid.SetColumn(myBorder, 1);
			gridContainer.Children.Add(myBorder);
			//myBorderをグリッドに追加
			Grid.SetColumn(ParentCvs, 2);
			gridContainer.Children.Add(ParentCvs);

			//メインウィンドウにgridContainerをコンテンツとして入れる
			this.Content = gridContainer;
		}
	}
}
