Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading user information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

XAML in .NET 4

19 minutes, 54 seconds


Right click “Save as…”

This isn't your Grandpa's XAML!

XAML in .NET 4 is much more than just a Reader and Writer and also is now being consumed by many technologies including Silverlight, WCF, WF and of course WPF. Rob Relyea and Mike Shim came by to talk about what's new in XAML for 2009 and beyond.

For instructions on how to download and install Visual Studio 2010 Beta 1 check out this episode of 10-4.


Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
  • Allan LindqvistaL_ Kinect ftw

    wow thats great stuff! :O the decoupling of xaml from wpf/wf is really great news Smiley the new features are really great too , the object-to-xaml story espeacially Smiley will vs provide intellisense to when editing those xaml files too? :O it would be really cool to hear about the xaml editor changes in vs as well Smiley maybe thats coming up Smiley

  • stevo_stevo_ Human after all

    Pretty much one of my hobby projects has been waiting on this.. whats the story on using the .net 4.0 beta with vs2008?

  • Thanks Adam for having us on Channel 9!

    There are more details about XAML2009 and System.Xaml.dll on my WindowsClient.Net blog.

    aL_ - VS intellisense (and Blend intellisense) don't support all the next XAML2009 features yet, but will in the future. (See XAML2009 isn't everywhere yet...).  Mark Wilson-Thomas, soon to be on Channel 9, should cover some of the enhancements in VS 2010 for XAML, including intellisense for MarkupExtensions.

    stevo_ - VS 2008 can't target .NET 4.0 applications, but VS 2010 can target 2.0, 3.0, 3.5, 4.0 applications!  Multitargeting...gotta love it!

    Thanks, Rob Relyea

  • bitdisasterbitdisaster Nokia Developer Ambassador

    Sounds great!!!
    Is there any getting started to use XAML in a custom file format???

  • section31-
    Not positive what you mean by that question...so I'll discuss custom file formats & XAML a bit.  Please rephrase/expand on that question if I don't cover what you want to know.

    There are many custom file formats that you could imagine that hold "XAML Data".  WPF uses BAML.  Baml2006Reader surfaces up objects, members & values.  Used in conjunction with the XamlObjectWriter, you can read BAML and have it create object graphs.

    If you wanted to invent your own file format to replace XAML's XML format, you would build a new subclass of System.Xaml.XamlReader and System.Xaml.XamlWriter.

    Thanks, Rob

  • stevo_stevo_ Human after all

    Hi Rob,
    I think he was asking for some getting started with System.Xaml, how would you get your custom xaml markup into object graphs etc.. I have a few questions regarding xaml but I'm not sure where to ask them.. for example - for my own xaml, could the files be .xaml extensions? how do you enable designer support then? I would guess visual studio is told to use certain designers for certain root object types?

    What about case sensitivity? could I have <something /> vs <Something /> ? what about intercepting how attributes are mapped to properties, so that for example I could have an attribute that would represent an elements 'markup name', so that I could say:

    public bool XamlRocks { get; set; }

    and have:

    <something xaml-rocks="true" /> (ideally with intellisense)

    And if this is possible, presumably via a custom reader- how do I tell the ide to use this reader to understand MY xaml?

    I know theres a lot of questions there and I'm being cheeky asking but if you could point me perhaps to a 'xaml community' Tongue Out..

    Cheers in advance.

  • bitdisasterbitdisaster Nokia Developer Ambassador

    Ok, what I have is a given object graph and I would like to use XAML to  de-/serialize it. But also take advantage of validation and intellisense. Currently I use my own XML dialect and I have to implement all the parsing stuff by my self. One feature I would like to have  the ability to just write changes from the object graph to they specific spot in the XML and not to generate the whole document and loose all the user formatting. I guess XAML is able to do it?

  • Where can I download that tool ? I would love to see the code generated from XAML and play around with it.

  • Allan LindqvistaL_ Kinect ftw

    ok but i got the impression that this stuff was going to be availalble in .net 4 Smiley what parts will available and what parts wont? do you see VS support in the vs10 timeframe or a later version?

  • freefly-

    The source code for that tool (XamlT.Pad) is here: http://robrelyea.com/demos/xamlT.Pad/XamlT.Pad.Beta1.zip. It requires .NET 4 Beta1 to run.

    I'll be exploring some of the code in there on my blog over the next few days/weeks...but you don't need to wait for me.

    Thanks, Rob


  • section31-

    Yes, using a XAML based dialect has some advantages:

    • You don't need to write your own load/save code.
    • VS has a XAML editor that will provide intellisense for your vocabulary.

    If you want to be able to write down just a part of an object graph, that we can do, but stiching that into an existing XAML text document is an advanced scenario that Cider/Blend do a lot of work to support.  Likely you'd need to be more advanced in your usage of System.Xaml, perhaps maintaining a XamlDom and correlating that with the ObjectGraph and the text file -- like Cider/Blend do.  If you want to go do that, we hope that System.Xaml.dll helps you do that...and we'd love feedback for that scenario.

    Thanks, Rob

  • stevo_-

    Custom Formats

    If I wanted to build a new file format called .myFormat that looked like this:

        .Background Red

    Instead of the same XAML XML format:

        <Button Background="Red">Ok</Button>

    I would build a XamlMyFormatReader that subclasses System.Xaml.XamlReader.
    It would then need to parse the .myFormat file and do the necessary work to pass the appropriate XAML node stream on each call to XamlMyFormatReader.Read().

    A user would then do something like this:

    XamlMyFormatReader mfReader = new XamlMyFormatReader("page.myFormat");
    StackPanel sp = (StackPanel)XamlServices.Load(mfReader);

    Note: the Cider/Blend designer has no plans to support other XAML formats with intellisense, designer support.  So building your own text based format for XAML for WPF/Silverlight is likely not very useful.  There are other scenarios where this flexibility will be beneficial though.

    Case Insensitive, Different Markup Names

    Yes, you could write a custom XamlSchemaContext that would enable those scenarios...case insensitive searches, paying attention to an attribute that says a different name.  You would need to make XamlXmlReader use your custom schema context in order to work though.

    Yes, it is possible...is it a good idea, I don't think so.

    And, no, intellisense definitely wouldn't respect that.  The IDE/XAML Editor has no pluggability to take arbitrary XamlReaders.

    Xaml Community

    We don't have an official MSDN forum devoted to XAML.  Right now, I'd recommend commenting on my blog or posting questions to the WPF Forum in MSDN...

    Thanks, Rob

  • aL_-

    See "XAML2009 isn't everywhere yet" and ask questions on that post for questions about what is in .NET 4 or not.  VS support is not planned in VS10 timeframe.

    Thanks, Rob

  • Very cool. My last project was an Excel app that presented data using WPF using a custom UI specified in loose XAML files. Was very pleased with the result, but have to admit that it was flakier than I'd have liked if given bad markup (I lost count of how many times I had to go delete x:Class!) The new XAML APIs look ideal for that sort of scenario, so I'll definitely be checking them out.

  • stevo_stevo_ Human after all

    Thanks Rob,

    Yes perhaps not a good idea, but it was based on the problem being markup first, its a shame you can't specify a designer xaml reader for a specific root type.

  • Will the System.Xaml assembly only be available for the new .Net 4.0 CLR, or will you also compile a version that we could execute on a good old .Net 2.0 CLR ?

    We would really like to use System.Xaml in web applications on the server side, but .Net 4.0 is not likely to be avaible on our production servers before at least two years.

    In fact, we are in the process of writing our own XAML parser, and it seems such a waste of time regarding the great work you have already done in System.Xaml ...

    If not, is there any chance that the System.Xaml source code should one day be released under an open source license like other parts of the .Net platform ?

    Thanks for your advice.

  • Hi Rob, thank you very much.. I recently started learning about WPF and I will be following your blog. Looks very good. one thing missing though.. you may need to format the code on your blog nicely... Big Smile 

    Thanks again..for the nice tool... looking forward to see the new code changes ...

  • LaurentP -

    You aren't the first to request a .NET 3.x version of System.Xaml.dll.  Currently we have no plans to offer that, but I'd love to know what server side scenarios you'd like to use XAML for. 

    Of course, you can use XamlReader.Load() from PresentationFramework.dll for .NET 3.x now...

    We have no plans to release System.Xaml.dll individually under any open source license...whatever the rest of .NET does, we'll do.

    Thanks, Rob

  • Our scenario for using XAML on the server side is the following one :

    v2 of our in-house web framework (used internally by several hundred developpers) has two important requirements :
    - the applications must support both a Silverlight or a standard HTML front end, dependending on the channel used to access them (with a common declarative view model, but two different presentation templates)
    - the server-side HTML control tree should be described in a much more strongly typed way than with traditional ASP.Net webform syntax (which is only about building a big string ...) if we want to be able to handle backward compatibility

    The natural choice was thus to use a XAML syntax to describe a strongly typed control tree for our HTML rendering engine, and even to reuse all of the "logical tree optimization" notions offered by Silverlight & WPF : resources, styles, controls, templates, and dependency properties (knowledge & tools reuse).

    Even if we reused the same concepts, in a client/server HTML world, the implementation of all these notions is very different than what it is in WPF. For example, the property system and the styles are much more complicated to handle (javascript & CSS generation), and have a slightly different meaning.

    We first thought we would be able to use PresentationFramework.dll to load our XAML page descriptions, but AFAIK, there is no way for XamlReader.Load to initialize attached properties, styles ... without depending on the property system, binding expressions ... of WPF (objects derived from FrameworkElement), which does not fit our needs.

    I really think there is a strong need in the community for a .Net 2.0 compatible version of System.Xaml.dll, as it could help speed up XAML adoption for a wider range of scenarios. I can see ISVs producing XAML-based tools also being stuck with a .Net 2.0 CLR on their clients machine for a while.

    Thanks, Laurent.

  • LaurentP-

    Very intersting scenario.  I occasionally ask the ASP.NET team why they don't use XAML...

    XamlReader.Load in v3 can likely meet most of your needs.  An attached property doesn't need a DependencyProperty, it can work with just the static setter and getter methods. As long as you can build your XAML Vocabulary (set of elements/properties) with the right CLR shape, PresentationFramework.dll may be ok for you.

    Thanks for the feedback.. we'll keep listening to feedback about this.  Our list of future work items is large...to take advantage of our new XAML infrastructure...

    Thanks, Rob

  • sweswe

    "Love xaml", haha.

  • stevo_stevo_ Human after all

    Rob, this is EXACTLY what my pet project is about.. hence why I wanted a custom schema to parse lower case and also handle scenarios like this:

    <meta http-equiv="something" />

    Xaml won't like that because http-equiv cant possibly map to a cli? valid attribute, but I COULD intercept the member lookup and have an overload so my meta class may look something like this:

    class Meta
      string HttpEquiv { get; set; }

    This is also why I would love to plugin to the xaml viewer so that I could literally hand it a valid xhtml document and it would parse it happily.

    The only things I'm thinking that may cause problems are how client markup (ie the rendered xhtml) namespaces will work, but I was thinking that the handling Type would be able to pick if it rendered the namespace back out in the output.

    (does this sound like a valid scenario to mould xaml into (even as a prototype) or is this still a bad idea?)

  • Loading an XHTML document into an object graph, is one thing.  Getting that rendered, is likely a much bigger chunk of work.

    You likely could build a set of types that represented the xhtml data, with the appropriate properties.
    Using XmlnsDefinitionAttribute, you could map the xhtml namespace to your clr namespaces.

    You could write a custom XamlSchemaContext to support case-insensitve lookup and support for "-" in a property name.

    Seems less crazy than I thought before because you aren't trying to do this generally, but in order to consume a file type.

    However, you should contrast this option with other XML to Object migration technologies like XML to LinQ and XmlSerialization...and Mike thinks there may be a HTML to LinQ on codeplex (or the like).

    Thanks, Rob

  • stevo_stevo_ Human after all

    Thanks for the reply, yea theres plenty of options for serialization, but I don't want xaml purely to load the xhtml (to say do transforms with) and render it, I actually want to see how possible it is to build a asp.net style stack out of this, so having a control system that similar to wpf, builds up its 'response' from primative xhtml types (ie, good separation of behavior and the template).

    Markup extensions and attached properties would be used to control other concerns, for example you could have attached properties to identify cachability of page areas, or markup extensions to express client side bindings (evaluated by javascript).

    I figured my biggest problem would be performance (aside from actually implementing such a concept), given that the source is completely translated into an object graph, 'evaluated' then rendered back to pure xhtml.. but I was wondering if you could create an object graph once for the page (perhaps even do some forms of persistence of the graph) and re-use the object graph over and over (making it much more like a template).

Remove this comment

Remove this thread


Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.