グラフィックス 目次

Similar documents
グラフィックス 目次

グラフィックス 目次

XAML Do-It-Yourself シリーズ 第 8 回ゕニメーション -1-

WPFの初歩の初歩

Userコントロール

XAML Do-It-Yourself シリーズ 第 12 回 3D グラフィックス -1-

WPF/Silverlightのスタイルやアニメーション

VB.NET解説

Chart3D for WPF/Silverlight

グラフィックス 目次

XAML Do-It-Yourself 第 3 回ベントとトリガー XML Do-It-Yourself 第 3 回目は ベント処理とトリガーについて学習します Windows フォームゕプリケーションでは たとえば ボタンが押された というベントに対応する処理 ( ベントハンドラー ) を記述する

SharpShooter Reports.WPF 基本的な使い方 Last modified on: November 15, 2012 本ドキュメント内のスクリーンショットは英語表記ですが SharpShooter Reports JP( 日本語版 ) では日本語で表示されます

新しいイテレーション型開発

Design with themes — Part 1: The Basics

64bit環境で32bitコンポーネントの利用

XAML Do-It-Yourself シリーズ 第 7 回テンプレート -1-

Design with themes — Part 1: The Basics

VB実用Ⅲ⑩ フリーデータベースⅡ

Format text with styles

XAML Do-It-Yourself シリーズ 第 11 回 2D グラフゖックス -1-

グラフィックス

TileView for WPF/Silverlight

Carousel for WPF/Silverlight

XAML Do-It-Yourself シリーズ 第 1 回 XAML 概要 -1-

Sparkline for WPF

Visual Basic 資料 電脳梁山泊烏賊塾 コレクション初期化子 コレクション初期化子 初めに.NET 版の Visual Basic では 其れ迄の Visual Basic 6.0 とは異なり 下記の例の様に変数宣言の構文に 初期値を代入する式が書ける様に成った 其の際 1 の様に単一の値

(Microsoft Word - Word\216\300\217K\212\356\221b1.doc)

グラフィックス 目次

Visual Studio 2010 Ready Day ブレークアウトセッション概要

FileExplorer for ASP.NET Web Forms

4. 下のような画面が表示され 写真を挿入する為に ファイル / ディスク ボタンをクリックします 5. 下のような画面が表示され 挿入する写真を選択し 挿入 ボタンをクリックします ( 写真は Ctrl キー または Shift キーを使うことで 複数枚選択することができます ) (2)

データベースプログラミング

Microsoft Word - VB.doc

Microsoft Word -

Blue Asterisk template

Sharing the Development Database

ListViewコントロール

NotifyIconコントロール

< F2D D E6A7464>

DockControl for WPF/Silverlight

wpf #wpf

ルーレットプログラム

構造体

<4D F736F F F696E74202D F56504E90DA91B1835C CC834E838A B838B837D836A B2E >

ArcGIS Runtime SDK for WPF インストールガイド (v10.2.5)

Microsoft Word - M067【テキスト】PowerPoint2010(前).docx

RAYOUT

Prog2_4th

目次 1. プロフィール画像工房の概要 3 2. プロフィール画像の作成 8 3. プロフィール画像の登録 まとめ 27 レッスン内容 プロフィール画像工房 インターネット上に提供されているさまざまなサービス ( これ以降 サービス と記述します ) を利用するときには 利用するユーザー

目次 はじめに... 3 システムの必要条件... 4 ライセンス認証... 4 アクティベーション... 6 開発... 7 手順 1. アプリケーションの作成... 7 手順 2. データソースの作成と代入... 7 手順 3. テンプレートの作成 手順 4. レポートビューアの追加

マクロの実行許可設定をする方法 Excel2010 で 2010 でマクロを有効にする方法について説明します 参考 URL:

Slider for ASP.NET Web Forms

Prog2_5th

PowerPoint プレゼンテーション

CodeGear Developer Camp

Visual Studio Do-It-Yourself 第 9 回ユーザーコントロール 第 6 回のリソースから第 8 回のテンプレートで さまざまな方法でコントロールをカスタマズできるこ とを学びました 今回のテーマであるユーザーコントロールは 既存の一つのコントロールをカスタマ ズするのではな

IBM Business Process Manager CSS による Coach レイアウト制御ガイド WebSphere 2014 IBM Corporation

MISAO with WPF

シヤチハタ デジタルネーム 操作マニュアル

Prog2_15th

図 2 Excel スプレッドシートの世界 のウィンドウ 図 3 Visual Basic の世界 のウィンドウ 図 3 の VBA ウィンドウは 図 2 の Excel ウィンドウのメニューの ツール をクリックし 開か れるプルダウンメニューで マクロ /Visual Basic Editor

PYTHON 資料 電脳梁山泊烏賊塾 PYTHON 入門 ゲームプログラミング スプライト スプライト Pygame では pygame.sprite を用いる事でスプライトの管理 描画 衝突判定等を簡単に行う事が出来る 此れを利用してキャラクター操作に関する各種機能をスプライトクラスとして 1 個

2004年度情報リテラシーⅢ

グラフィックス 目次

WPF アプリケーションの 多言語切替

Prog2_12th

ふれんずらくらく流通図面マニュアル

OTRS10 他社システムOTRS呼出利用手順書

( 目次 ) 1. はじめに 開発環境の準備 仮想ディレクトリーの作成 ASP.NET のWeb アプリケーション開発環境準備 データベースの作成 データベースの追加 テーブルの作成

C#の基本

第 1 章 : はじめに RogueWave Visualization for C++ の Views5.7 に付属している Views Studio を使い 簡単な GUI アプリケーションの開発手順を紹介します この文書では Windows 8 x64 上で Visual Studio2010

ブロック パニック

Consuming a simple Web Service

目次 第 1 章概要....1 第 2 章インストールの前に... 2 第 3 章 Windows OS でのインストール...2 第 4 章 Windows OS でのアプリケーション設定 TP-LINK USB プリンターコントローラーを起動 / 終了するには

ファイルを直接編集する画面を切り替えることができる. 図 3 標準のレイアウトを削除する (2) グラフィカル レイアウト画面で LinearLayout(Vertical) を追加するパレットウィンドウの レイアウト の中にある LinearLayout(Vertical) をドラッグして, 編集

(Microsoft Word - Excel\216\300\217K\212\356\221b1.doc)

Tabs for ASP.NET Web Forms

MS Office オートメーション

ICONファイルフォーマット

Expander for ASP.NET Web Forms

アメブロは そのままで使えるおしゃれなテンプレートが豊富にそろっているのが特徴ですがさらにデザインをカスタマイズすることによって 見やすく集客しやすいブログにすることができます このテキストでは 2016 年 3 月にリリースされた CSS 編集用デザイン を使用して あなただけのデザインにアメブロ

OutlookBar for WPF/Silverlight

Microsoft Word - VisualC++利用法2.doc

2002年度情報リテラシーⅢ

正規表現応用

Prog2_6th

Word2007 Windows7 1 パンジーを描こう 暮らしのパソコンいろは 早稲田公民館 ICT サポートボランティア

サンプル CSS1 入力フィールドの輪郭 (outline) のトランジション 入力フィールドをクリックすると変化します InputOutlineTransition の説明 HTML の記述 (InputOutlineTransition.html) id 属性 field の div 要素を作り

グラフィックス 目次

ER/Studio Data Architect 2016 の新機能

Prog2_6th

平成 30 年度 プログラミング研修講座 岩手県立総合教育センター

Silverlightでメディア配信をはじめよう

PowerPoint プレゼンテーション

(Microsoft Word - Excel\211\236\227p6\217\315.docx)

Wordでアルバム作成

Field Logic, Inc. 標準モード 3D モデル作成 配置編 Field Logic, Inc. 第 1 版

PowerPoint2007基礎編

Microsoft Word - P doc

Microsoft Word IL3_1.doc

Transcription:

WPF チュートリアル を使用したボタンの作成 此のチュートリアルでは Windows Presentation Foundation(WPF) アプリケーションで使用するアニメーションボタンの作成方法に付いて説明する 此のチュートリアルでは カスタマイズされたボタンリソースを作成するのにスタイルとテンプレートを使用する 此れに依り コードを再利用したり ボタンロジックをボタン宣言から分離したり出来る様に成る 此のチュートリアルは総て Extensible Application Markup Language() で記述されて居る 此のチュートリアルでは Extensible Application Markup Language() を Microsoft Visual Studio に入力するか コピーと貼り付けを行う事でアプリケーションを作成する手順に付いて説明する 同じアプリケーションをデザインツール (Microsoft Expression Blend) を使用して作成する方法の詳細に付いては チュートリアル : Microsoft Expression Blend を使用してボタンを作成する を参照され度い 次の図は 完成したボタンの外観を示して居る 基本ボタンの作成 先ず 新しいプロジェクトを作成し ウィンドウにボタンを幾つか追加する 新しい WPF プロジェクトを作成し ウィンドウにボタンを追加するには 1.Visual Studio を起動する 2. 新しい WPF プロジェクトの作成 :[ ファイル ] メニューの [ 新規 ] をポイントし [ プロジェクト ] をクリックする [WPF アプリケーション ] テンプレートを選択し プロジェクトに AnimatedButton と謂う名前を付ける 此れで アプリケーションのスケルトンが作成される -1-

3. 既定の基本ボタンの追加 : 此のチュートリアルで必要と成るファイルは 総てテンプレートに用意されて居る ソリューションエクスプローラで MainWindow.xaml をダブルクリックして開く MainWindow.xaml には 既定で Grid 要素が有る Grid 要素を削除し 次の強調表示されたコードを Window1.xaml に入力するかコピーして貼り付けて Extensible Application Markup Language() ページにボタンを幾つか追加する <Window x:class="mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="AnimatedButton" Height="300" Width="300" Background="Black"> <!-- Buttons arranged vertically inside a StackPanel. --> <StackPanel HorizontalAlignment="Left"> <Button>Button 1</Button> <Button>Button 2</Button> <Button>Button 3</Button> </StackPanel> </Window> F5 キーを押してアプリケーションを実行する 次の図の様なボタンのセットが表示される 基本ボタンを作成したので MainWindow.xaml ファイルに対する作業は終わりで有る 此れ以降は ボタンのスタイルとテンプレートを定義する Application.xaml ファイルを中心に説明する 基本プロパティの設定 次に 此等のボタンに付いて 外観とレイアウトをコントロールする為のプロパティを幾つか設定する 其の際 プロパティをボタン別に設定するのではなく アプリケーション全体のボタンプロパティを定 -2-

義するリソースを使用する アプリケーションリソースは Web ページ用の外部カスケードスタイルシート (CSS) と概念的には似て居るが 此のチュートリアルを通じて説明される様に リソースの方がカスケードスタイルシート (CSS) 依り遥かに強力で有る リソースの詳細に付いては リソース を参照され度い ボタンの基本プロパティを設定する為のスタイルを使用するには 1.Application.Resources ブロックの定義 :Application.xaml を開き 次の強調表示されたマークアップが含まれて居ない場合は追加する <Application x:class="application" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <!-- アプリケーション全体のリソースを此処で定義する --> </Application.Resources> </Application> リソースのスコープは リソースを定義する場所で決定される Application.xaml ファイルの Application.Resoureses で定義されたリソースは アプリケーションの何処ででも使用出来る リソースのスコープの定義の詳細に付いては リソース を参照され度い 2. スタイルの作成と 基本プロパティ値の定義 : 次のマークアップを Application.Resources ブロックに追加する 此のマークアップは アプリケーションに含まれる総てのボタンに適用される Style を作成する 此のスタイルに依り ボタンの Width は 90 に設定され Margin は 10 に設定される <Application.Resources> <Style TargetType="Button"> <Setter Property="Width" Value="90" /> <Setter Property="Margin" Value="10" /> </Style> </Application.Resources> TargetType プロパティは Button 型の総てのオブジェクトに適用されるスタイルを指定する 各 Setter は Style に異なるプロパティ値を設定する 従って 此の時点では アプリケーションに含まれる総てのボタンの幅は 90 で 余白は 10 で有る F5 キーを押してアプリケーションを実行すると 次の様なウィンドウが表示される -3-

スタイルを使用すると 他にも様々な事が出来る 例えば 対象オブジェクトを微調整する方法が各種用意されて居る他 複雑なプロパティ値を指定したり 或るスタイルを他のスタイルの入力として使用したりする事も出来る 詳細に付いては スタイルとテンプレート を参照され度い 3. スタイルのプロパティ値のリソースへの設定 : リソースを使用する事で 一般的に定義されるオブジェクトや値を簡単に再利用出来る 複雑な値をリソースを使用して定義する事は コードをモジュール化するのに大変便利で有る 次の強調表示されたマークアップを Application.xaml に追加する <Application.Resources> <LinearGradientBrush x:key="graybluegradientbrush" StartPoint="0,0" EndPoint="1,1"> <GradientStop Color="DarkGray" Offset="0" /> <GradientStop Color="#CCCCFF" Offset="0.5" /> <GradientStop Color="DarkGray" Offset="1" /> </LinearGradientBrush> <Style TargetType="{x:Type Button}"> <Setter Property="Background" Value="{StaticResource GrayBlueGradientBrush}" /> <Setter Property="Width" Value="80" /> <Setter Property="Margin" Value="10" /> </Style> </Application.Resources> Application.Resources ブロックの直下に "GrayBlueGradientBrush" と謂うリソースが作成されて居る 此のリソースは 水平方向のグラデーションを定義する 此のリソースは Background プロパティのボタンスタイルの Setter の内部から等 アプリケーションの何処からでもプロパティ値として使用出来る 此れで 総てのボタンが此のグラデーションの Background プロパティを持つ様に成った -4-

F5 キーを押してアプリケーションを実行する 結果は次の様に成る ボタンの外観を定義するテンプレートの作成 此処では ボタンの外観 ( プレゼンテーション ) カスタマイズするテンプレートを作成する ボタンプレゼンテーションは 四角形等のコンポーネントを含む幾つかのオブジェクトで構成され ボタンに固有の外観を指定する 此れ迄 アプリケーションに於けるボタンの外観のコントロールは ボタンのプロパティを変更する事に制限されて居た ボタンの外観を更に大きく変更するには何うすれば良いか テンプレートを使用すると オブジェクトのプレゼンテーションを強力にコントロール出来る テンプレートはスタイル内で使用出来るので スタイルが適用される総てのオブジェクト ( 此のチュートリアルではボタン ) にテンプレートを適用出来る ボタンの外観を定義するテンプレートを使用するには 1. テンプレートのセットアップ :Button 等のコントロールには Template プロパティが有るので テンプレートのプロパティ値は Style で Setter を使用して設定した他のプロパティと同じ様にして定義出来る 次の強調表示されたマークアップをボタンスタイルに追加する <Application.Resources> <LinearGradientBrush x:key="graybluegradientbrush" StartPoint="0,0" EndPoint="1,1"> <GradientStop Color="DarkGray" Offset="0" /> <GradientStop Color="#CCCCFF" Offset="0.5" /> <GradientStop Color="DarkGray" Offset="1" /> </LinearGradientBrush> <Style TargetType="{x:Type Button}"> -5-

<Setter Property="Background" Value="{StaticResource GrayBlueGradientBrush}" /> <Setter Property="Width" Value="80" /> <Setter Property="Margin" Value="10" /> <Setter Property="Template"> <Setter.Value> <!-- The button template is defined here. --> </Setter.Value> </Setter> </Style> </Application.Resources> 2. ボタンプレゼンテーションの変更 : 此の時点でテンプレートを定義する必要が有る 次の強調表示されたマークアップを追加する 此のマークアップは 角が丸い 2 つの Rectangle 要素を指定し 続いて DockPanel を指定する DockPanel はボタンの ContentPresenter をホストする為に使用される ContentPresenter にはボタンのコンテンツが表示される 此のチュートリアルでは コンテンツはテキスト ("Button 1" "Button 2" "Button 3") で有る テンプレートコンポーネント ( 四角形と DockPanel) は総て Grid 内部にレイアウトされる <Setter.Value> <ControlTemplate TargetType="Button"> <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" ClipToBounds="True"> <!-- Outer Rectangle with rounded corners. --> <Rectangle x:name="outerrectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stroke="{TemplateBinding Background}" RadiusX="20" RadiusY="20" StrokeThickness="5" Fill="Transparent" /> <!-- Inner Rectangle with rounded corners. --> <Rectangle x:name="innerrectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stroke="Transparent" StrokeThickness="20" Fill="{TemplateBinding Background}" RadiusX="20" RadiusY="20" /> <!-- Present Content (text) of the button. --> <DockPanel Name="myContentPresenterDockPanel"> <ContentPresenter x:name="mycontentpresenter" Margin="20" Content="{TemplateBinding Content}" TextBlock.Foreground="Black" /> </DockPanel> </Grid> </ControlTemplate> </Setter.Value> -6-

F5 キーを押してアプリケーションを実行する 結果は次の様に成る 3. テンプレートへのグラス効果の追加 : 次に グラスを追加する 先ず グラスグラデーション効果を作成するリソースを幾つか作成する 此等のグラデーションリソースを Application.Resources ブロック内の何処か ( 先頭部分が良い ) に追加する <Application.Resources> <GradientStopCollection x:key="myglassgradientstopsresource"> <GradientStop Color="WhiteSmoke" Offset="0.2" /> <GradientStop Color="Transparent" Offset="0.4" /> <GradientStop Color="WhiteSmoke" Offset="0.5" /> <GradientStop Color="Transparent" Offset="0.75" /> <GradientStop Color="WhiteSmoke" Offset="0.9" /> <GradientStop Color="Transparent" Offset="1" /> </GradientStopCollection> <LinearGradientBrush x:key="myglassbrushresource" StartPoint="0,0" EndPoint="1,1" Opacity="0.75" GradientStops="{StaticResource MyGlassGradientStopsResource}" /> <!-- スタイルや他のリソースは此処より下に記述 --> 此等のリソースは ボタンテンプレートの Grid に挿入する四角形の Fill として使用される 次の強調表示されたマークアップをテンプレートに追加する <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" ClipToBounds="True"> -7-

<!-- Outer Rectangle with rounded corners. --> <Rectangle x:name="outerrectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stroke="{TemplateBinding Background}" RadiusX="20" RadiusY="20" StrokeThickness="5" Fill="Transparent" /> <!-- Inner Rectangle with rounded corners. --> <Rectangle x:name="innerrectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stroke="Transparent" StrokeThickness="20" Fill="{TemplateBinding Background}" RadiusX="20" RadiusY="20" /> <!-- Glass Rectangle --> <Rectangle x:name="glasscube" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" StrokeThickness="2" RadiusX="10" RadiusY="10" Opacity="0" Fill="{StaticResource MyGlassBrushResource}" RenderTransformOrigin="0.5,0.5"> <Rectangle.Stroke> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <LinearGradientBrush.GradientStops> <GradientStop Offset="0.0" Color="LightBlue" /> <GradientStop Offset="1.0" Color="Gray" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Rectangle.Stroke> <!-- These transforms have no effect as they are declared here. The reason the transforms are included is to be targets for animation (see later). --> <Rectangle.RenderTransform> <TransformGroup> <ScaleTransform /> <RotateTransform /> </TransformGroup> </Rectangle.RenderTransform> <!-- A BevelBitmapEffect is applied to give the button a "Beveled" look. --> <Rectangle.BitmapEffect> <BevelBitmapEffect /> </Rectangle.BitmapEffect> </Rectangle> <!-- Present Text of the button. --> <DockPanel Name="myContentPresenterDockPanel"> <ContentPresenter x:name="mycontentpresenter" Margin="20" Content="{TemplateBinding Content}" TextBlock.Foreground="Black" /> </DockPanel> </Grid> </ControlTemplate> </Setter.Value> -8-

"glasscube" の x:name プロパティを持つ四角形の Opacity は 0 なので 此のサンプルを実行すると グラス四角形は最前面にオーバーレイ表示されない 此れは ユーザーがボタンを使用して対話操作を行う場合に付いて 後でトリガーをテンプレートに追加するからで有る 但し Opacity 値を 1 に変更してアプリケーションを実行すると ボタンの外観を直ぐに確認出来る 次の図を参照され度い 次の手順に進む前に Opacity を 0 に戻す ボタンの対話機能の作成 此処では マウスポインターをボタンに合わせてクリックする等のユーザーアクションに対応して プロパティ値を変更してアニメーションを実行するプロパティトリガー 及び イベントトリガーを作成する 対話機能 ( マウスオーバー マウスリーブ クリック等 ) を追加する簡単な方法は テンプレートやスタイルの内部にトリガーを定義する事で有る Trigger を作成するには ボタンの IsMouseOver プロパティが true に等しいと謂ったプロパティ " 条件 " を作成する 次に トリガー条件が true に成った時に実行される setter( アクション ) 定義する ボタンの対話機能を作成するには 1. テンプレートトリガーの追加 : 次の強調表示されたマークアップをテンプレートに追加する <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" ClipToBounds="True"> <!-- Outer Rectangle with rounded corners. --> <Rectangle x:name="outerrectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stroke="{TemplateBinding Background}" RadiusX="20" RadiusY="20" StrokeThickness="5" Fill="Transparent" /> -9-

<!-- Inner Rectangle with rounded corners. --> <Rectangle x:name="innerrectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stroke="Transparent" StrokeThickness="20" Fill="{TemplateBinding Background}" RadiusX="20" RadiusY="20" /> <!-- Glass Rectangle --> <Rectangle x:name="glasscube" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" StrokeThickness="2" RadiusX="10" RadiusY="10" Opacity="0" Fill="{StaticResource MyGlassBrushResource}" RenderTransformOrigin="0.5,0.5"> <Rectangle.Stroke> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <LinearGradientBrush.GradientStops> <GradientStop Offset="0.0" Color="LightBlue" /> <GradientStop Offset="1.0" Color="Gray" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Rectangle.Stroke> <!-- These transforms have no effect as they are declared here. The reason the transforms are included is to be targets for animation (see later). --> <Rectangle.RenderTransform> <TransformGroup> <ScaleTransform /> <RotateTransform /> </TransformGroup> </Rectangle.RenderTransform> <!-- A BevelBitmapEffect is applied to give the button a "Beveled" look. --> <Rectangle.BitmapEffect> <BevelBitmapEffect /> </Rectangle.BitmapEffect> </Rectangle> <!-- Present Text of the button. --> <DockPanel Name="myContentPresenterDockPanel"> <ContentPresenter x:name="mycontentpresenter" Margin="20" Content="{TemplateBinding Content}" TextBlock.Foreground="Black" /> </DockPanel> </Grid> <ControlTemplate.Triggers> <!-- Set action triggers for the buttons and define what the button does in response to those triggers. --> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> -10-

2. プロパティトリガーの追加 : 次の強調表示されたマークアップを ControlTemplate.Triggers ブロックに追加する <ControlTemplate.Triggers> <!-- Set properties when mouse pointer is over the button. --> <Trigger Property="IsMouseOver" Value="True"> <!-- Below are three property settings that occur when the condition is met (user mouses over button). --> <!-- Change the color of the outer rectangle when user mouses over it. --> <Setter Property ="Rectangle.Stroke" TargetName="outerRectangle" Value="{DynamicResource {x:static SystemColors.HighlightBrushKey}}" /> <!-- Sets the glass opacity to 1, therefore, the glass "appears" when user mouses over it. --> <Setter Property="Rectangle.Opacity" Value="1" TargetName="glassCube" /> <!-- Makes the text slightly blurry as though you were looking at it through blurry glass. --> <Setter Property="ContentPresenter.BitmapEffect" TargetName="myContentPresenter"> <Setter.Value> <BlurBitmapEffect Radius="1" /> </Setter.Value> </Setter> </Trigger> <ControlTemplate.Triggers/> F5 キーを押してアプリケーションを実行し マウスポインタをボタンに合わせた時の効果を確認する 3. フォーカストリガーの追加 : 次に ボタンにフォーカスが有る場合 ( ユーザーがクリックした後等 ) を処理する同様の setter を追加する <ControlTemplate.Triggers> <!-- Set properties when mouse pointer is over the button. --> <Trigger Property="IsMouseOver" Value="True"> <!-- Below are three property settings that occur when the condition is met (user mouses over button). --> <!-- Change the color of the outer rectangle when user mouses over it. --> <Setter Property ="Rectangle.Stroke" TargetName="outerRectangle" Value="{DynamicResource {x:static SystemColors.HighlightBrushKey}}" /> <!-- Sets the glass opacity to 1, therefore, the glass "appears" when user mouses over it. --> <Setter Property="Rectangle.Opacity" Value="1" TargetName="glassCube" /> <!-- Makes the text slightly blurry as though you were looking at it through blurry glass. --> -11-

<Setter Property="ContentPresenter.BitmapEffect" TargetName="myContentPresenter"> <Setter.Value> <BlurBitmapEffect Radius="1" /> </Setter.Value> </Setter> </Trigger> <!-- Set properties when button has focus. --> <Trigger Property="IsFocused" Value="true"> <Setter Property="Rectangle.Opacity" Value="1" TargetName="glassCube" /> <Setter Property="Rectangle.Stroke" TargetName="outerRectangle" Value="{DynamicResource {x:static SystemColors.HighlightBrushKey}}" /> <Setter Property="Rectangle.Opacity" Value="1" TargetName="glassCube" /> </Trigger> </ControlTemplate.Triggers> F5 キーを押してアプリケーションを実行し 孰れかのボタンをクリックする クリックされた後でもフォーカスが有るので ボタンは強調表示された儘に成る 別のボタンをクリックすると 新しいボタンにフォーカスが移り 其れ迄のボタンはフォーカスを失う 4.MouseEnter と MouseLeave へのアニメーションの追加 : 次に トリガーにアニメーションを追加する 次のマークアップを ControlTemplate.Triggers ブロックの中に追加する <!-- Animations that start when mouse enters and leaves button. --> <EventTrigger RoutedEvent="Mouse.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard Name="mouseEnterBeginStoryboard"> <Storyboard> <!-- This animation makes the glass rectangle shrink in the X direction. --> <DoubleAnimation Storyboard.TargetName="glassCube" Storyboard.TargetProperty= "(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" By="-0.1" Duration="0:0:0.5" /> <!-- This animation makes the glass rectangle shrink in the Y direction. --> <DoubleAnimation Storyboard.TargetName="glassCube" Storyboard.TargetProperty= "(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" By="-0.1" Duration="0:0:0.5" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseLeave"> <EventTrigger.Actions> <!-- Stopping the storyboard sets all animated properties back to default. --> <StopStoryboard BeginStoryboardName="mouseEnterBeginStoryboard" /> </EventTrigger.Actions> </EventTrigger> -12-

グラス四角形は マウスポインタをボタンに合わせると小さく成り ポインターが離れると標準サイズに戻る ポインターをボタンに合わせた時 (MouseEnter イベントが発生した時 ) にトリガーされるアニメーションは 2 つ有る 此等のアニメーションは グラス四角形を夫々 X 軸及び Y 軸方向に縮小する DoubleAnimation 要素のプロパティは Duration と By で有る Duration はアニメーションが 0.5 秒間発生する様に指定し By はグラスが 10% 縮小される様に指定する 2 番目のイベントトリガー (MouseLeave) は 単純に最初のイベントを停止する Storyboard を停止すると アニメーション化された総てのプロパティが既定値に戻る 従って ユーザーがポインターをボタンから離すと ボタンはマウスポインタをボタンに合わせる前の状態に戻る アニメーションの詳細に付いては アニメーションの概要 を参照され度い 5. ボタンがクリックされた時のアニメーションの追加 : 最後の手順は ユーザーがボタンをクリックした時のトリガーの追加で有る 次のマークアップを ControlTemplate.Triggers ブロックの中に追加する <!-- Animation fires when button is clicked, causing glass to spin. --> <EventTrigger RoutedEvent="Button.Click"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="glassCube" Storyboard.TargetProperty= "(Rectangle.RenderTransform).(TransformGroup.Children)[1].(RotateTransform.Angle)" By="360" Duration="0:0:0.5" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> F5 キーを押してアプリケーションを実行し 孰れかのボタンをクリックする ボタンをクリックすると グラス四角形が回転する http://msdn.microsoft.com/ja-jp/library/bb613545(v=vs.110).aspx http://msdn.microsoft.com/ja-jp/library/ee649089(v=vs.110).aspx -13-