480 likes | 655 Views
CL24. XAML Futures for Microsoft .NET, Microsoft Silverlight and Tools. Michael.Shim@microsoft.com Program Manager, http://michaelshim.com/blog Rob.Relyea@microsoft.com Architect, http://robrelyea.com/blog . XAML Status & Futures. XAML @ 3 year mark We’ll focus on 5 areas today
E N D
CL24 XAML Futuresfor Microsoft .NET,Microsoft Silverlight and Tools Michael.Shim@microsoft.com Program Manager, http://michaelshim.com/blog Rob.Relyea@microsoft.com Architect, http://robrelyea.com/blog
XAML Status & Futures • XAML @ 3 year mark • We’ll focus on 5 areas today • Runtime Parsing • Static Analysis • Compile Time • Design Time • Localization Static Analysis Design Time Compile Time Runtime Localization
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 for UI or Non-UI • 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 PF.dll WF, WCF,More… WPF PresentationFramework.dll (PF.dll) Workflow BAMLengine XAML engine BAML engine XOML engine PC.dll PresentationCore.dll (PC.dll) XomlTypeInfo WindowsBase.dll WindowsBase.dll System.Xaml.dll XamlTypeInfo XAML engine XamlTypeInfo Mscorlib, System, System.Xml Mscorlib, System, System.Xml 4 3.x
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 Items Types • Objects are instances of XamlTypes • Members are instances of XamlMembers Object Member Value
XAML Node Stream StartObject StartMember Canvas Children StartObject StartMember Value Button “Green” Background StartMember Value “OK” Content StartObject StartMember Value “Cancel” Content Button
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.
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 1 • <StyleTargetType="Button" > • <SetterProperty="Background" • Value="Red" /> • </Style> 2 3 1) Typetype = xamlTypeResolver.Resolve("Button"); 2) Value of Style.TargetType determined by calling IAmbientProviderto 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 1 • <Button Click=“foo” /> • <Button Click=“{l:EventWire foo}” /> • <Button Height=“{l:GetValue tb1.Height}” /> 2 3 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).
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 1 2 3 4 5 6
XAML 2009 EnhancementsRecap 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
Silverlight XAML Improvement Plan Starts working: Invalid XAML stops working: Duplicate property setting … • Text as content <Button>Hello</Button> • All MarkupExtensions work in ObjectElement syntax • Better debuggability • Better error messages and locations • Throws on invalid XAML earlier • … Will have tools to help improve the validity of your XAML.
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 • 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 announcing Provides Static Analysis, Localization, & XamlDom for .NET/Silverlight XAML
XamlDom • Represents the XAML Node stream in a tree • XML nodes • (XmlReader-> XDocument) • XAML nodes (S.X.XamlReader -> XamlDom) StartObject StartMember Canvas Children StartObject StartMember Value Button “Green” Background StartMember Value “OK” Content StartObject StartMember Value “Cancel” Content Button Background “Green” Button “OK” Content Canvas Children Button “Cancel” Content
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 <ButtonBackground="Red">Click Me!</Button> XamlXmlWriterxamlXmlWriter = newXamlXmlWriter("myfile.xaml", schemaContext); XamlTypebuttonType = schemaContext.GetXamlType(typeof(Button)); XamlMemberbackgroundMember = buttonType.GetMember("Background"); XamlMembercontentMember = 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(); newXamlDomObject(typeof(Button), schemaContext, newXamlDomMember("Background", "Red"), newXamlDomMember("Content", "Click Me!") ); XamlDomServices.Save(domObject, "myfile.xaml");
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 • publicabstractclassBaseXamlRule: BaseIntrospectionRule • { • publicabstractvoidCheckXaml(XamlDomObjectrootObjectNode, • XamlSchemaContextschemaContext, • stringresourceName); • }
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
UISchemaContext • XamlSchemaContextthat 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
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
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 MarkupExtensionintellisense • 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
Approaches to XAML UI Localization x:Uid {MarkupExtension} {Binding} {StaticResource} to resources in ResourceDictionaries {x:Static} to strongly typed ResX resources {my:Loc} • LocBaml
x:Uid vs {MarkupExtension} (1 of 2) x:Uid <Button Click=“handleOk” x:Uid=“button1”> Ok </Button> {MarkupExtension} <Button Click=“handleOk” Content=“{SomeMEcontentValue}” />
XAML Localization Status • Silverlight • Build: None • Runtime: {Binding} • PostBuild: None • .NET • Build: None • Runtime: {Binding}, {SR}, {my:Loc} • PostBuild: LocBaml, 3rd Parties
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 BuildTimeLocalization of a Silverlight Application demo
Pain points • Internal and External Pain Points • Assembly dependency • File format (.csv) • Tools support • Visual designer • BamlWriter • Metadata + overriding • Uid generation • Fallback
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 at MicrosoftPDC.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/learn Built by Developers for Developers….
Discussion • Nowand in Web lounge • Engage on blogs, XAML Toolkit forum