Design Time Compile Time Runtime Static Analysis Localization.

Post on 17-Jan-2016

225 views 0 download

transcript

XAML Futuresfor Microsoft .NET,Microsoft Silverlight and Tools

Michael.Shim@microsoft.comProgram Manager, http://michaelshim.com/blog

Rob.Relyea@microsoft.comArchitect, http://robrelyea.com/blog

CL24

XAML Status & Futures

> XAML @ 3 year mark> We’ll focus on 5 areas today

> Runtime Parsing> Static Analysis> Compile Time> Design Time> Localization

Design Time

Compile Time Runtime

Static Analysis

Localization

XAML Runtimes

Runtime Improvements (Parsers)

> .NET 4 using System.Xaml.dll> Ready for UI and non-UI> More services available to

MarkupExtensions & TypeConverters> XAML2009 Language Features

> Silverlight XAML Futures> Status> Improvements> Direction

> XAML ready types or frameworks only need: mscorlib, System, System.Xml, System.Xaml

> Removing the XAML engine out of Fx Libraries> XamlReader.Load still in PF.dll

XAML for UI or Non-UI

WF, WCF,

More…

PresentationCore.dll (PC.dll)

PresentationFramework.dll (PF.dll)

XAML engine

3.x

WindowsBase.dll

XamlTypeInfo

Mscorlib, System, System.Xml

BAMLengine

PC.dll

PF.dll

WindowsBase.dll

BAML engine

4

System.Xaml.dll

XamlTypeInfo

XAML engine

Mscorlib, System, System.Xml

WPFWorkflo

w

XOML engin

e

Xoml

TypeInfo

XAML Data Model: O-M-V + Types

O-M-V> Root Object> Objects have Members> Members contain Objects and/or Values> Some Objects are Collections> Collections have a property

to hold their ItemsTypes> Objects are instances of XamlTypes> Members are instances of XamlMembers

Object Member Value

XAML Node Stream

StartObject

Value

StartMember

StartObject StartMember

ValueStartMember

ValueStartObject StartMember

Background

ChildrenCanvas

Button

Button

Content

Content

“Green”

“OK”

“Cancel”

>>FUTURE

Working with XAML Node Streams

Enables:> Scenario: XamlPad that strips event

handlers> Scenario: Adding Script to XAML

> Note: a technology demo, not best practice for most applications.

Adding Script to XAML

demo

>>FUTURE

More Power for MarkupExtensions and TypeConverters> V3 MEs and TCs

> IXamlTypeResolver, IUriContext & IProvideValueTarget

> V4 MEs and TCs> IRootObjectProvider> IXamlNameResolver & IXamlNameProvider

(Save)> IAmbientProvider> IDestinationTypeProvider> IXamlNamespaceProvider &

INamespacePrefixLookup (Save)> IXamlSchemaContextProvider> IXamlObjectWriterFactory

IXamlTypeResolver, IAmbientProvider, IXamlSchemaContextProvider<Style TargetType="Button" > <Setter Property="Background" Value="Red" /> </Style>

3

1

2

1) Type type = xamlTypeResolver.Resolve("Button"); 2) Value of Style.TargetType determined by calling IAmbientProvider to find instances of Style.TargetType up the parse stack. 3)xamlSchemaContext = ixscp.SchemaContext;xamlType = xamlSchemaContext.GetXamlType(typeof(Button));xamlMember = xamlType.GetMember("Background");value=xamlMember.TypeConverter.ConverterInstance.ConvertFrom(…);

IRootObjectProvider, IXamlNameResolver<Button Click=“foo” /><Button Click=“{l:EventWire foo}” /><Button Height=“{l:GetValue tb1.Height}” />

3

1

2

1) Parser looks for foo method on Root object.2) IRootObjectProvider can get root object.3) IXamlNameResolver can find element with Name of tb1 (even it is hasn’t been parsed yet).

>>FUTURE

More Power for MarkupExtensions and TypeConverters> V3 MEs and TCs

> IXamlTypeResolver, IUriContext & IProvideValueTarget

> V4 MEs and TCs> IRootObjectProvider> IXamlNameResolver & IXamlNameProvider

(Save)> IAmbientProvider> IDestinationTypeProvider> IXamlNamespaceProvider &

INamespacePrefixLookup (Save)> IXamlSchemaContextProvider> IXamlObjectWriterFactory

3

1 2

45

6

XAML 2009 Enhancements Recap from PDC08> Improved named references (x:Reference)> Full generics support (x:TypeArguments)> Built-in types (x:String, etc…)> Support arbitrary dictionary key types

(x:Key)> Support events without compilation> Define new properties (x:Members,

x:Property)> Use non-default constructors

(x:Arguments)> Use factory methods (x:FactoryMethod)

Note: Compilers + Designers in .NET 4, VS2010, & Blend won’t have XAML2009 support at RTM.

Runtime Parser Improvements

> .NET 4 using System.Xaml.dll> Ready for UI and non-UI> More services available to

MarkupExtensions, TypeConverters> XAML2009 Language Features

> Silverlight XAML Futures> Status> Improvements> Direction

>>FUTURE

Silverlight XAML Improvement Plan

Starts working:> Text as content

<Button>Hello</Button>> All MarkupExtensions

work in ObjectElement syntax

> Better debuggability> Better error messages and

locations> Throws on invalid XAML

earlier> …

Invalid XAML stops working:

> Duplicate property setting> …

Will have tools to help improve the validity of your XAML.

>>FUTURE

Silverlight XAML Direction

> In the future, moving the Silverlight XAML parser to the same XAML Node infrastructure

> Better compatibility with .NET XAML and ability to evolve quickly

> Scenarios will drive future addition of > More XAML2006 features> XAML2009 features

XAML Static Analysis

>>FUTURE

XAML Static Analysis

> Declarative UI provides great opportunities for analysis, however, we don’t support FxCop on XAML today.

> We are going to make it easy> XamlDom> FxCop & XAML

> WPF & Silverlight integration

Microsoft XAML Toolkit

Provides Static Analysis, Localization, & XamlDom for .NET/Silverlight XAML

announcing

>>FUTURE

XamlDom Represents the XAML Node stream in a tree• XML nodes (XmlReader ->XDocument)• XAML nodes

(S.X.XamlReader -> XamlDom)

StartObject

Value

StartMember

StartObjectStartMem

ber

ValueStartMem

ber

ValueStartObjectStartMem

ber

Background

ChildrenCanva

s

Button

Button

Content

Content

“Green”

“OK”

“Cancel”

XDObject XDMember

XDObject

XDMember Value

XDMember Value

XDObject XDMember Value

Canvas

Children

Button

Button

Background

“Green”

Content

“OK”

Content

“Cancel”

>>FUTURE

XamlDom

> Like XLinq for XDocument, can use Linq against XamlDom

> XamlDom useful for Tools> XAML Designers (Blend/VS)> Static Analysis> Transformations (Converters)

Querying the XamlDom

demo

XamlDom Functional Construction

new XamlDomObject(typeof(Button), schemaContext, new XamlDomMember("Background", "Red"), new XamlDomMember("Content", "Click Me!"));XamlDomServices.Save(domObject, "myfile.xaml");

XamlXmlWriter xamlXmlWriter = new XamlXmlWriter("myfile.xaml", schemaContext);XamlType buttonType = schemaContext.GetXamlType(typeof(Button));XamlMember backgroundMember = buttonType.GetMember("Background");XamlMember contentMember = buttonType.GetMember("Content");xamlXmlWriter.WriteStartObject(buttonType);xamlXmlWriter.WriteStartMember(backgroundMember);xamlXmlWriter.WriteValue("Red");xamlXmlWriter.WriteEndMember();xamlXmlWriter.WriteStartMember(contentMember);xamlXmlWriter.WriteValue("Click Me!");xamlXmlWriter.WriteEndMember();xamlXmlWriter.WriteEndObject();xamlXmlWriter.Close();

<Button Background="Red">Click Me!</Button>

>>FUTURE

Tooling Silverlight XAML

> .NET & Silverlight metadata are different> ContentPropertyAttribute is in two

different assemblies (System.Xaml.dll vs System.Windows.dll)

> Silverlight > Some markup extensions don’t have CLR

types> Some types are missing metadata (like

TypeConverterAttribute)

> System.Xaml.dll needs a Silverlight XamlSchemaContext> Tools can rely on the

SilverlightSchemaContext

XAML FxCop

demo

BaseXamlRule

public abstract class BaseXamlRule : BaseIntrospectionRule{ public abstract void CheckXaml(XamlDomObject rootObjectNode,

XamlSchemaContext schemaContext,

string resourceName);}

>>FUTURE

XAML FxCop

• Processes all XAML/BAML files in a Resource and calls CheckXaml

• CTP supports WPF, Silverlight, and Workflow

• Considering a visitor pattern as well

>>FUTURE

UISchemaContext

> XamlSchemaContext that works with both WPF & Silverlight> Translates types between both worlds> Write one FxCop rule against WPF or

Silverlight, works against both platforms> Only useful for static analysis

>>FUTURE

FxCop Details

> Working with FxCop team on better integration (resource granularity, suppressions, etc…)

> CTP includes following FxCop support:> BaseXamlRule> Rules to improve Silverlight content> XAML validation rule> UISchemaContext

XAML Compilers

> WPF 4> Fixed some impactful bugs

> Out of memory, incremental build issues, CompilerGenerated attributes for FxCop

> Visual Studio/MSBuild support multi-targeting> Couldn’t afford to support XAML2009 in compiler &

BAML> WPF 3.x Compiler Update

> Port fixes to 3.x XAML compiler coming early next year

> Silverlight 4> Minor bug fixes

> Workflow 4> New XAML compiler

>>FUTURE

WPF/Silverlight Compiler Futures

> Improved compilers on horizon for both

> Goals> Based on System.Xaml Node stream> Better validation

> Additional XAML Validation component that can be used elsewhere (FxCop, Designers, localization, etc…)

> Improve generated files (.g.cs/.g.vb) (XmlnsDefinitionAttribute, RuntimeNameProperty, etc…)> x:Property

> Add XAML2009 support for WPF

XAML Designers

> VS2010/Blend: Integration with designers and runtime parsers> WPF Data/Control Template editing is significantly

faster> Visual Studio 2010

> Added MarkupExtension intellisense> Supports SL & WPF XAML> Better performance for intellisense> Fixed bugs in parser

> Blend> Added intellisense in XAML view> Better incremental parse/update> Better support for attached properties> Fixed bugs in parser

XAML Localization

Approaches to XAML UI Localization

x:Uid> LocBaml

{MarkupExtension}> {Binding}> {StaticResource} to

resources in ResourceDictionaries

> {x:Static} to strongly typed ResX resources

> {my:Loc}

x:Uid vs {MarkupExtension} (1 of 2)x:Uid<Button Click=“handleOk” x:Uid=“button1”> Ok</Button>

{MarkupExtension}<Button Click=“handleOk” Content=“{SomeME contentValue}” />

x:Uid vs {MarkupExtension} (2 of 2)Criteria x:Uid {ME}

Impact on XAML Better Poor

Cider/Blend Value Editing Experience

Better Poor

Runtime Performance Better Ok(lite + heavy)

Post-Build Localization enabled

Yes No

Injection of Values No* -> Yes

No

Support for RichText Yes No

Support for Element Reordering

Yes No

XAML Localization Status

> Silverlight> Build: None> Runtime: {Binding}> PostBuild: None

> .NET> Build: None> Runtime: {Binding}, {SR}, {my:Loc}> PostBuild: LocBaml, 3rd Parties

>>FUTURE

XAML Localization Plan

> Silverlight> Build: Support x:Uid based localization> Runtime: {Binding}> PostBuild: Support x:Uid based

localization> .NET

> Build: Support x:Uid based localization> Runtime: {Binding}, {SR}, {my:Loc}> PostBuild: Improve Pain Points

Prototype of BuildTime Localization of a Silverlight Application

demo

>>FUTURE

Pain points

> Internal and External Pain Points> Assembly dependency> File format (.csv)> Tools support> Visual designer> BamlWriter> Metadata + overriding> Uid generation> Fallback

>>FUTURE

Plans for XAML Localization

> Focus very soon on this area for WPF & Silverlight

> Engage with community for feedback> Deliver Microsoft.Xaml.Localization.dll

as part of a future XAML Toolkit CTP

Call for Action

> Begin using .NET 4 Beta 2 & System.Xaml.dll

> Download Microsoft XAML Toolkit CTP for Static Analysis and XamlDom> http://code.msdn.microsoft.com/XAML> Write tools for .NET/Silverlight XAML> Write FxCop rules> Give feedback on XamlDom

> Give feedback to improve XAML development

YOUR FEEDBACK IS IMPORTANT TO US!

Please fill out session evaluation

forms online atMicrosoftPDC.com

Learn More On Channel 9

> Expand your PDC experience through Channel 9

> Explore videos, hands-on labs, sample code and demos through the new Channel 9 training courses

channel9.msdn.com/learnBuilt by Developers for Developers….

Discussion

> Now and in Web lounge> Engage on blogs, XAML Toolkit forum

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.