CL24: XAML Futures for Microsoft .NET,Microsoft Silverlight ...

CL24: XAML Futures for Microsoft .NET,Microsoft Silverlight ...

CL24 XAML Futures for Microsoft .NET, Microsoft Silverlight and Tools [email protected] Program Manager, http://michaelshim.com/blog [email protected] Architect, http://robrelyea.com/blog XAML Status & Futures > XAML @ 3 year mark > Well focus on 5 areas today > Runtime Parsing > Static Analysis > Compile Time

> Design Time > Localization Static Analysis Design Time Compile Time Runtime Localizatio n 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 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 XOML

engin e Xom l Type Info Workflo Workflo w w BAML XAML engine engine Presentation

Framework.dll (PF.dll) PresentationCore. dll (PC.dll) XamlTypeInf o WindowsBase.dll Mscorlib, System, System.Xml 3.x BAML engine PF.dll

PC.dll Windows Base.dll WPF WF, WCF, More XamlTypeInf XAML o engine System.Xaml.dll Mscorlib, System, System.Xml 4

XAML Data Model: O-M-V + Types O-M-V Object Member Valu > Root Object e > 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

XAML Node Stream StartObject Canvas StartObject Button StartMember Children StartMember Value Background Green StartMember

Value Content OK StartObject StartMember Value Button Content

Cancel >>FUTUR E 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

>>FUTUR E 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 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.ConvertFro m(); IRootObjectProvider, IXamlNameResolver

x:Property) Use non-default constructors (x:Arguments) Use factory methods (x:FactoryMethod) Note: Compilers + Designers in .NET 4, VS2010, & 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

>>FUTUR E Silverlight XAML Improvement Plan Starts working: > Text as content > 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. Silverlight XAML Direction >>FUTUR E

> 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 XAML Static Analysis > Declarative UI provides great >>FUTUR E

opportunities for analysis, however, we dont 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 >>FUTUR

E XamlDom StartObject StartMember Canva Children s StartObject StartMember Backgrou Button nd StartMember Content StartObject Button

StartMember Content Value Green Value OK Represents the XAML Node stream in a tree XML nodes (XmlReader -> XDocument) XAML nodes (S.X.XamlReader -> XamlDom)

Value Cancel XDMemb er XDObject XDObject Canva s XDMemb XDMemb er er

Children Button Backgrou nd XDMemb XDMemb er er Conten t XDObject

Button XDMemb XDMemb er er Conten t Value Green Value OK

Value Cancel XamlDom > Like XLinq for XDocument, can use Linq against XamlDom > XamlDom useful for Tools > XAML Designers (Blend/VS) > Static Analysis > Transformations (Converters) >>FUTUR E

Querying the XamlDom demo XamlDom Functional Construction 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(); new XamlDomObject(typeof(Button), schemaContext, new XamlDomMember("Background", "Red"), new XamlDomMember("Content", "Click Me!") ); XamlDomServices.Save(domObject, Tooling Silverlight XAML >>FUTUR E > .NET & Silverlight metadata are

different > ContentPropertyAttribute is in two different assemblies (System.Xaml.dll vs System.Windows.dll) > Silverlight > Some markup extensions dont have CLR types > Some types are missing metadata (like TypeConverterAttribute) > System.Xaml.dll needs a Silverlight XamlSchemaContext

> Tools can rely on the XAML FxCop demo BaseXamlRule public abstract class BaseXamlRule : BaseIntrospectionRule { public abstract void CheckXaml(XamlDomObject rootObjectNode, XamlSchemaContext schemaContext, string resourceName); } XAML FxCop

Processes all XAML/BAML files in a >>FUTUR E Resource and calls CheckXaml CTP supports WPF, Silverlight, and Workflow Considering a visitor pattern as well UISchemaContext >>FUTUR E > 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 FxCop Details >>FUTUR E > 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 > Couldnt 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 >>FUTUR E

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 {MarkupExtension} > LocBaml > {Binding} > {StaticResource} to resources in

ResourceDictionaries > {x:Static} to strongly typed ResX resources > {my:Loc} x:Uid vs {MarkupExtension} (1 of 2) x:Uid {MarkupExtension}

Recently Viewed Presentations