Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

WPF

ビハインドコードでjpgを表示する

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

マークアップでjpgを表示する

アプリ実行 プロジェクト jpgを追加する ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

DrawingBrushを使って塗りつぶし領域に合うようにスケーリングさせる

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

1つの図形を共有して敷き詰める

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

チェックボックスの外観をブラシのソースとして使用する

アプリ実行 起動 マウスオーバーでチェックボックスの外観が変わると追随する ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

複数の直線を引く

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

簡素化したベジエ曲線を描画する

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

楕円を指定された点まで描画する

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

ベジエ曲線を引く

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

直線を引く

アプリ実行 ソースコード App.xaml <Application x:Class="WpfApplication4.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

GridSplitterで領域のサイズを変更可能にする

アプリ実行 起動 スプリッタをドラッグ ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

GridでLive Messengerの画面構成を再現する

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

複数Gridで列サイズを共有する

アプリ実行 ソースコード App.xaml <Application x:Class="WpfApplication4.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

Gridの複数列でサイズを共有する

アプリ実行 ソースコード App.xaml <Application x:Class="WpfApplication4.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

Gridの楕円幅を最長のものに合わせる

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

Gridの列と行を割合で指定する

アプリ実行 ソースコード App.xaml <Application x:Class="WpfApplication4.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

UniformGridでグリッドレイアウトを実装する

UniformGridは基本的な機能しか提供しないので、Gridよりもパフォーマンス面で有利です。(2011/03/14追記) アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow…

WrapPanelで折り返しのレイアウトを実装する

アプリ実行 ソースコード App.xaml <Application x:Class="WpfApplication4.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

DockPanelでエクスプローラの画面構成を再現する

アプリ実行 ソースコード App.xaml <Application x:Class="WpfApplication4.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

Canvasを使ってコントロールをフローティングする

アプリ実行 ソースコード App.xaml <Application x:Class="WpfApplication4.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

Canvasにレイアウトする(その2)

アプリ実行 エッセンシャル WPF P.172より引用 ここでは、キャンバスは実際には高さがゼロですが、StackPanelによって表示全体に引き伸ばされています。 エッセンシャル WPF:Windows Presentation Foundation (Programmer’s SLECTION―Microsoft .net Develop…

Canvasにレイアウトする

アプリ実行 4つ全て指定すると、TopとLeftが優先されるようですね。 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

Zインデックスで重なりの順序を指定する

Zインデックス指定なし アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

LayoutTransformプロパティとRenderTransformプロパティの違い

アプリ実行 LayoutTransformプロパティを使用する(背景色緑)とレイアウトに前に適用されるので、描画に必要な領域が確保されます。 RenderTransformプロパティを使用する(背景色橙)とレンダリングの直前に適用されるので、領域は変わりません。 ソースコ…

ViewBoxでスペースにフィットするようにコンテンツを伸縮させる

アプリ実行 起動 サイズ変更 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

ScrollViewerでスクロール可能にする

アプリ実行 起動 スクロールバーが現れるまで[追加]ボタンでテキストボックスにテキスト追加 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

Popupでフローティングウィンドウを実装する

アプリ実行 起動 [表示]をチェック [表示]のチェックを外す ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

Borderで境界線を描画する

アプリ実行 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

ドラッグで移動可能な領域を実装する

アプリ実行 起動 ドラッグ ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml

ToolTipServiceを使用してツールチップの動作を変更する

アプリ実行 マウスオーバー テキストボックスの下部にツールチップが表示されます。 ソースコード App.xaml <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> </Application> MainWindow.xaml