WPF
WPF 3.5
3.5 の新機能
の新機能
WPF
WPF 3.5
3.5 の新機能
の新機能
川⻄ 川⻄ 裕幸裕幸 UX UX エバンジェリストエバンジェリスト デベロッパー&プラットフォーム統括本部 デベロッパー&プラットフォーム統括本部 マイクロソフト株式会社 マイクロソフト株式会社WPF 3.5 ?
WPF 3.5 ?
WPF 3.5 ?
WPF 3.5 ?
NET F
k 3 5
NET F
k 3 5 に含まれる
に含まれる WPF
WPF
.NET Framework 3.5
.NET Framework 3.5 に含まれる
に含まれる WPF
WPF
SP1 + SP1 + 新しいアセンブリ(新しいアセンブリ(System.Core.dllSystem.Core.dll など)など) LinqLinq はは System.Core.dllSystem.Core.dll に含まれるに含まれる
.NET Framework 3.0 SP1
.NET Framework 3.0 SP1 に含まれる
a e o 3 0 S
a e o 3 0 S
に含まれる WPF
に含まれる
に含まれる
WPF
Windows Server 2008 Windows Server 2008 Windows Vista SP1 Windows Vista SP1 Windows Vista SP1 Windows Vista SP1 ただし、 ただし、LinqLinq バインディングを使うときは注意バインディングを使うときは注意詳しくは
詳しくは Visual Studio 2008
Visual Studio 2008 ドキュメント
ドキュメント
詳しくは
詳しくは Visual Studio 2008
Visual Studio 2008 ドキュメント
ドキュメント
バージョン情報を参照 バージョン情報を参照
互換性
互換性
互換性
互換性
WPF 3 0
WPF 3 0 でビルドしたアプリは
でビルドしたアプリは WPF3 5
WPF3 5 上
上
WPF 3.0
WPF 3.0 でビルドしたアプリは
でビルドしたアプリは WPF3.5
WPF3.5 上
上
(
(ex. Vista SP1
ex. Vista SP1)で動作
)で動作
WPF 3.5
WPF 3.5 でビルドしたアプリは
でビルドしたアプリは WPF3.0
WPF3.0 上で
上で
は動作しない
は動作しない NET Framework 3 5
NET Framework 3 5 のインス
のインス
は動作しない、
は動作しない、.NET Framework 3.5
.NET Framework 3.5 のインス
のインス
トールが必要
トールが必要
新機能を使 ていなければ動作するかもしれない 新機能を使 ていなければ動作するかもしれない 新機能を使っていなければ動作するかもしれない 新機能を使っていなければ動作するかもしれない...新しいスキーマ
新しいスキーマ
http://schemas.microsoft.com/netfx/2007/xaml/presentation http://schemas.microsoft.com/netfx/2007/xaml/presentation http://schemas.microsoft.com/netfx/2007/xaml/presentation http://schemas.microsoft.com/netfx/2007/xaml/presentationこれまでのスキーマも有効
これまでのスキーマも有効
アプリケーション
アプリケーション モデル
モデル
アプリケ ション
アプリケ ション モデル
モデル
XBAP
XBAP
XBAP
XBAP
Firefox Firefox HTTP HTTP CookieCookie 部分信頼 部分信頼 WCF WCF サービスサービスAdd
Add--In
In サポート
サポート
dll dll を実⾏時に動的に統合できるを実⾏時に動的に統合できる dll dll を実⾏時に動的に統合できるを実⾏時に動的に統合できる部分信頼
部分信頼 WCF
WCF サービス
サービス
部分信頼
部分信頼 WCF
WCF サ ビス
サ ビス
ASP NET
ASP NET 中間アクセス権で動作するサ バ アプリで
中間アクセス権で動作するサ バ アプリで
ASP.NET
ASP.NET 中間アクセス権で動作するサーバーアプリで、
中間アクセス権で動作するサーバーアプリで、
WCF Service Model
WCF Service Model を使って基本
を使って基本 HTTP
HTTP サービスを作成
サービスを作成
インタ ネット
インタ ネット ゾ ン
ゾ ン アクセス権で動作するクライアン
アクセス権で動作するクライアン
インターネット
インターネット ゾーン
ゾーン アクセス権で動作するクライアン
アクセス権で動作するクライアン
ト
ト アプリ(
アプリ(ex. XBAP
ex. XBAP)は、
)は、WCF
WCF プロキシ経由で
プロキシ経由で HTTP
HTTP
サービスを利⽤
サービスを利⽤
サ ビスを利⽤
サ ビスを利⽤
部分信頼
部分信頼 フルサポート
フルサポート
部分信頼
部分信頼 フルサポ ト
フルサポ ト
BasicHttpBindingBasicHttpBinding, , WebHttpBindingWebHttpBinding
トランスポート
トランスポート セキュリティ
セキュリティ モードのみサポート
モードのみサポート
トランスポ ト
トランスポ ト セキュリティ
セキュリティ モ ドのみサポ ト
モ ドのみサポ ト
WSHttpBinding WSHttpBinding部分信頼⾮サポート
部分信頼⾮サポート
部分信頼⾮サポ ト
部分信頼⾮サポ ト
NetTcpBindingAdd
Add--In
In
Add
Add In
In
WPF
WPF は
は Add
Add In
In を使って
を使って UI
UI を表⽰できる
を表⽰できる
WPF
WPF は
は Add
Add--In
In を使って
を使って UI
UI を表⽰できる
を表⽰できる
UI UI を返すを返す AddAdd--InIn ロードする条件によって変化する ロードする条件によって変化する UIUI ロ ドする条件によって変化する ロ ドする条件によって変化する UIUI UI UI であるである AddAdd--InIn 同じ 同じ UIUI を表⽰を表⽰ ex.ex.カラーピッカーカラーピッカーF
kEl
t
F
kEl
t を継承したクラス
を継承したクラス
FrameworkElement
FrameworkElement を継承したクラス
を継承したクラス
Shape, Control, User Control, Panel Shape, Control, User Control, Panel
⼿順
⼿順
⼿順
⼿順
パイプラインの作成 パイプラインの作成 契約の宣⾔ 契約の宣⾔ 契約の宣⾔ 契約の宣⾔ AddAdd--InIn はは FrameworkElementFrameworkElement をを INativeHandleContractINativeHandleContract にに 変換して返す(あるいは⾃分⾃⾝を変換して渡す) 変換して返す(あるいは⾃分⾃⾝を変換して渡す) 返された(あるいは渡された) 返された(あるいは渡された) INativeHandleContractINativeHandleContract をを 返された(あるいは渡された) 返された(あるいは渡された) INativeHandleContractINativeHandleContract をを FrameworkElement FrameworkElement に変換に変換 ホストアプリは返された(あるいは渡された) ホストアプリは返された(あるいは渡された) F kEl t F kEl t を表⽰を表⽰ FrameworkElement FrameworkElement を表⽰を表⽰
データ
データ
デ タ
デ タ
ビジネス
ビジネス オブジ クト検証
オブジ クト検証
ビジネス
ビジネス オブジェクト検証
オブジェクト検証
IDataErrorInfo IDataErrorInfo {Binding{Binding ValidatesOnDataErrorsValidatesOnDataErrors=true}=true}
Linq
Linq および
および Xlinq
Xlinq バインディング
バインディング サポート
サポート
Linq
Linq および
および Xlinq
Xlinq バインディング
バインディング サポ ト
サポ ト
Path=Element[content].Attribute[
Path=Element[content].Attribute[urlurl].Value].Value
XML (DOM)
XML (DOM) バインディング性能改善
バインディング性能改善
XML (DOM)
XML (DOM) バインディング性能改善
バインディング性能改善
DataSet
DataSet バインディング性能改善
バインディング性能改善
データ
データ
デ タ
デ タ
デバ グの改善
デバ グの改善
デバッグの改善
デバッグの改善
バンディング バンディング トレーストレース PresentationTraceSources.TraceLevel PresentationTraceSources.TraceLevelLow, Medium, High Low, Medium, High
<Window x:Class=“SampleApplication.Window1”
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas microsoft com/winfx/2006/xaml
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:diag=“clr‐namespace:System.Diagnostics;assembly=WindowsBase”> <Button Background=“{Binding Path=ProductColor, di P t ti T S T L l Hi h”/ diag:PresentationTraceSource.TraceLevel=High”/> </Window>
Binding
Binding の新しいプロパティ
の新しいプロパティ
ValidatesOnExceptions ValidatesOnExceptionspp ValidatesOnDataErrors ValidatesOnDataErrorsテキスト
テキスト
テキスト
テキスト
T tB
T tB
の
の IME
IME サポ ト
サポ ト
TextBox
TextBox の
の IME
IME サポート
サポート
FrameworkTextComposition FrameworkTextCompositionに新しいプロパティに新しいプロパティ CompositionOffset CompositionOffset CompositionLenght CompositionLenght ResultOffset ResultOffset ResultLength ResultLength IME
IME で⼊⼒中、で⼊⼒中、TextInputTextInput, , TextInputUpdateTextInputUpdate, , TextInputStart TextInputStart イベントが発⽣するととき、イベントが発⽣するととき、 T tC iti E tA T tC iti T tC iti E tA T tC iti として使⽤として使⽤ TextCompositionEventArgs.TextComposition TextCompositionEventArgs.TextComposition として使⽤として使⽤
RichTextBox
RichTextBoxの改善
の改善
UIElement UIElement がインラインで可能がインラインで可能 カスタム カスタム TextElementTextElementが可能が可能サウンド
サウンド
サウンド
サウンド
応答⾳再⽣⽤の新しいクラス
応答⾳再⽣⽤の新しいクラス
応答⾳再⽣⽤の新しいクラス
応答⾳再⽣⽤の新しいクラス
SoundPlayerAction SoundPlayerAction <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > <Page.Triggers> <EventTrigger RoutedEvent="Button.Click" SourceName="clickButton"> <EventTrigger.Actions> <SoundPlayerAction Source="media¥lowbat.wav"/> </EventTrigger Actions> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Button.MouseEnter" SourceName="hoverButton"> <EventTrigger.Actions> <SoundPlayerAction Source="media¥tada.wav"/> </EventTrigger.Actions> </EventTrigger> </Page.Triggers> </Page.Triggers> <StackPanel Width="200"> <Button Name="clickButton">Click to Play Sound</Button> B tt N "h B tt " H t Pl S d /B tt <Button Name="hoverButton">Hover to Play Sound</Button> </StackPanel> </Page>パフォーマンス
パフォーマンス
パフォ マンス
パフォ マンス
レイヤ ウ ンドウのハ ドウ ア化
レイヤ ウ ンドウのハ ドウ ア化
レイヤーウィンドウのハードウェア化
レイヤーウィンドウのハードウェア化
パフォーマンス
パフォーマンス
パフォ マンス
パフォ マンス
レイヤ ウ ンドウのハ ドウ ア化
レイヤ ウ ンドウのハ ドウ ア化
レイヤーウィンドウのハードウェア化
レイヤーウィンドウのハードウェア化
KB938660 KB938660 でも解決でも解決3
3D
D
System.Windows.Media.Media3D.Visual3DSystem.Windows.Media.Media3D.Visual3DSystem.Windows.Media3D.ModelVisual3DSystem.Windows.Media3D.ModelVisual3D3
3D
D
System.Windows.UIElemt3D System.Windows.UIElemt3D System.Windows.Media.Media3D.ContainerUIElemt3D System.Windows.Media.Media3D.ContainerUIElemt3D System.Windows.Media3D.ModelVisual3D System.Windows.Media3D.ModelVisual3D System.Windows.Media.Media3D.ModelUIElement3D System.Windows.Media.Media3D.ModelUIElement3D System.Windows.Media3D.Viewport2DVisual3D System.Windows.Media3D.Viewport2DVisual3DUIElement3D
UIElement3D(仮想)
(仮想)
C t i UIEl t3D M d lUIEl t3D C t i UIEl t3D M d lUIEl t3D ContainerUIElement3D, ModelUIElement3D ContainerUIElement3D, ModelUIElement3D ⼊⼒、フォーカス、イベントをサポートする ⼊⼒、フォーカス、イベントをサポートするModelVisual3DModelVisual3D O M d lU d O M d lU d II lidlid M d lM d lメソ ドを持メソ ドを持 OnModelUpdateOnModelUpdate, , InvalidateModelInvalidateModelメソッドを持つメソッドを持つ
Viewport2DVisual3D
Viewport2DVisual3D
(機能する)
(機能する)VisualVisualが張れるが張れるModelVisual3DModelVisual3D 3D 3D上のインタラクティブな上のインタラクティブな2D2Dコンテンツコンテンツ 33 上のインタラクティブな上のインタラクティブな ンテンツンテンツ
GeneralTransform3D
GeneralTransform3D(仮想)
(仮想)
新しい座標変換クラス 新しい座標変換クラス 新しい座標変換クラス 新しい座標変換クラス GeneralTransform3DTo2D, GeneralTransform2DTo3D GeneralTransform3DTo2D, GeneralTransform2DTo3DUIElement3D
UIElement3D
UIElement3D
UIElement3D
UIEl
t
UIEl
tと同等のイベントハンドリング
と同等のイベントハンドリング
UIElement
UIElementと同等のイベントハンドリング
と同等のイベントハンドリング
交差テスト⽤コードを書く必要はもうない 交差テスト⽤コードを書く必要はもうない 内部階層のルーティング 内部階層のルーティング イベントも処理イベントも処理 レイアウト機能はない レイアウト機能はないUIElement3D
UIElement3D その
その11
UIElement3D
UIElement3D その
その11
H dli
E
t i 3
H dli
E
t i 3 D S
D S
l
l
Handling Events in 3
Handling Events in 3--D Sample
D Sample
<ModelUIElement3D
<ModelUIElement3D MouseDownMouseDown “Cube1MouseDown”>“Cube1MouseDown”> <ModelUIElement3D
<ModelUIElement3D MouseDownMouseDown=“Cube1MouseDown”>=“Cube1MouseDown”> <ModelUIElement3D.Transform><ModelUIElement3D.Transform>
<TranslateTransform3D <TranslateTransform3D OffsetZOffsetZ=“1.5” />=“1.5” /> </ModelUIElement3D Transform>
</ModelUIElement3D Transform> </ModelUIElement3D.Transform> </ModelUIElement3D.Transform> <ModelUIElement3D.Model><ModelUIElement3D.Model>
<GeometryModel3D Geometry="{<GeometryModel3D Geometry="{StaticResourceStaticResource CubeMeshCubeMesh}">}"> <GeometryModel3D Material>
<GeometryModel3D Material>
<GeometryModel3D.Material><GeometryModel3D.Material>
<<DiffuseMaterialDiffuseMaterial x:Name=“cube1Material” Brush=“Blue” />x:Name=“cube1Material” Brush=“Blue” /> </GeometryModel3D.Material></GeometryModel3D.Material> </GeometryModel3D> </GeometryModel3D> </GeometryModel3D></GeometryModel3D> </ModelUIElement3D.Model></ModelUIElement3D.Model> </ModelUIElement </ModelUIElement33D>D>
private void Cube1MouseDown(object sender,
private void Cube1MouseDown(object sender, MouseButtonEventArgsMouseButtonEventArgs e)e) {{ cube1Material.Brush = cube1Material.Brush = ( b 1M i l B h ( b 1M i l B h BB h Blh Bl ?? BB h R dh R d BB h Blh Bl )) (cube1Material.Brush ==
(cube1Material.Brush == Brushes.BlueBrushes.Blue ? ? Brushes.RedBrushes.Red : : Brushes.BlueBrushes.Blue);); }}
UIElement3D
UIElement3D その
その22
UIElement3D
UIElement3D その
その22
O M d lU d t O M d lU d t II lid t M d llid t M d lメソ ドによりメソ ドにより OnModelUpdateOnModelUpdate, , InvalidateModelInvalidateModelメソッドにより、メソッドにより、 データバインディングを使った通知が可能に データバインディングを使った通知が可能に プロパティ変更による⾃⼰変更が可能な プロパティ変更による⾃⼰変更が可能な UIElement3DUIElement3D 派⽣派⽣ プロパティ変更による⾃⼰変更が可能な プロパティ変更による⾃⼰変更が可能な UIElement3D UIElement3D 派⽣派⽣ クラスが作成できる クラスが作成できる <Slider Width=“300” Maximum=“60” Minimum=“‐60” Margin=“10” Value=“{Binding ElementName=MyCylinder, Path=Angle}”/> <Viewport3D Width=“480” Height=“400” Margin=“10” > <Viewport3D.Camera> <PerspectiveCamera Position=“0,3,10” FieldOfView=“45”/> </Viewport3D.Camera> l l li d “ li d ” / <local:Cylinder x:Name=“MyCylinder” /> <ModelVisual3D> <ModelVisual3D.Content>
<Di ti lLi ht C l “Whit ” Di ti “0 0 1”/> <DirectionalLight Color=“White” Direction=“0,0,‐1”/> </ModelVisual3D.Content>
</ModelVisual3D> </Viewport3D>
UIElement3D
UIElement3D その
その22
UIElement3D
UIElement3D その
その22
protected override void OnUpdateModel() { GeometryModel3D model = new GeometryModel3D(); model.Geometry = Tessellate(Angle); model.Material = new DiffuseMaterial(Brushes.Blue); Model = model; } i ipublic static readonly DependencyProperty AngleProperty = DependencyProperty.Register( “Angle“, typeof(double), typeof(Cylinder), P t M t d t (0 0 A l P t Ch d)) new PropertyMetadata(0.0, AnglePropertyChanged)); private static void AnglePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { { Cylinder s = (Cylinder)d; s.InvalidateModel(); } } public double Angle { get {return (double)GetValue(AngleProperty);} get {return (double)GetValue(AngleProperty);} set {SetValue(AngleProperty, value);} }
Viewport2DVisual3D
Viewport2DVisual3D
Viewport2DVisual3D
Viewport2DVisual3D
Vi
t3D
Vi
t3D 内でも
内でも Vi
Vi
l
l が使える
が使える
Viewport3D
Viewport3D 内でも
内でも Visual
Visual が使える
が使える
Binding
Binding が利⽤できる
gg が利⽤できる
が利⽤できる
が利⽤できる
イベントハンドラとコールバックが利⽤できる
イベントハンドラとコールバックが利⽤できる
ただし ただし PP ii イベントハンドラを使うことイベントハンドラを使うこと ただし、 ただし、Preview Preview イベントハンドラを使うことイベントハンドラを使うことViewport2DVisual3D
Viewport2DVisual3D
Viewport2DVisual3D
Viewport2DVisual3D
<Vi t2DVi l3D N " M d l1“ G t "{St ti R S }" > <Viewport2DVisual3D x:Name="myModel1“ Geometry="{StaticResource mySquare}" >
<Viewport2DVisual3D.Transform> <RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="-45" Axis="0 1 0" /> </RotateTransform3D.Rotation> </RotateTransform3D> </Viewport2DVisual3D Transform> </Viewport2DVisual3D.Transform> <Viewport2DVisual3D.Material> <DiffuseMaterial Brush="White" Viewport2DVisual3D.IsVisualHostMaterial="True"/> </Viewport2DVisual3D.Material> <StackPanel>
<TextBox Name="myInput" Background="White" Width="100" Height="20"/> <TextBlock Name="myText" Background="Red" Width="50" Height="50"
<TextBlock Name= myText Background= Red Width= 50 Height= 50 Text="{Binding ElementName=myInput, Path=Text}“ />
<Button PreviewMouseLeftButtonDown="Button_MouseLeftButtonDown"> Change Color / </Button> </StackPanel> </Viewport2DVisual3D>
GeneralTransform3D
GeneralTransform3D
GeneralTransform3D
GeneralTransform3D
3D
3D間
間 3D
3Dと
と2D
2D間の座標変換
間の座標変換
3D
3D間、
間、3D
3Dと
と2D
2D間の座標変換
間の座標変換
3D 3Dジオメトリの点などをジオメトリの点などを2D2D空間に座標変換したいとき便利空間に座標変換したいとき便利GeneralTransform3D
GeneralTransform3D
Visual3D TransformToAncestor(Visual3D) Visual3D TransformToAncestor(Visual3D) Visual3D.TransformToAncestor(Visual3D) Visual3D.TransformToAncestor(Visual3D) Visual3D.TransformToDescendant(Visual3D) Visual3D.TransformToDescendant(Visual3D)GeneralTransform3DTo2D
GeneralTransform3DTo2D
GeneralTransform3DTo2D
GeneralTransform3DTo2D
Visual3D.TransformToAncestor(Visual) Visual3D.TransformToAncestor(Visual) Canvas A DGeneralTransform2DTo3D
GeneralTransform2DTo3D
Visual.TransformToAncesterVisual.TransformToAncester(Visual3D)(Visual3D) Viewport3D
A n c e e s c e Visual.TransformToAncester Visual.TransformToAncester(Visual3D)(Visual3D) ModelVisual3D Parent s t o r e n d a ModelVisual3D Child r n t