locked
Parsing and displaying WPF XAML RRS feed

  • Question

  • Hi

       I'd like to be able to parse a XAML file containing WPF and then display this in a window, similar to what the XAML Cruncher program does.  Does anyone have some code to show how this is done, or is there a simple method call for displaying the result tree from a XamlReader call?

    Thanks

    [Tim]

    Sunday, June 19, 2011 12:18 AM

Answers

  • Hi Tbenner,

    I am not sure whether you have read the link carefully. But based on your description, as the link says you can use the XamlReader class to read the XAML as ab onject, then you can convert the object as the Type you want.

    Here is the link about XamlReader:
    http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlreader.aspx

    In the link there is a samle as follows:

    Button readerLoadButton = (Button)XamlReader.Load(xmlReader);
    I am not sure what is your type of 3D fugure, but you can do as the above code.

    Then you can add the type into your application and to display just as the button to show in your application. If any misunderstanding, please feel free let me know. Thanks.

     


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Sheldon _Xiao Wednesday, June 22, 2011 12:20 PM
    • Marked as answer by Aspen VJ Monday, June 27, 2011 2:38 AM
    Wednesday, June 22, 2011 5:53 AM

All replies

  • Hi tbenner,

    Based on your description, do you mean that you want to read XAML as string input and return an object graph?

    If so, I think you can try to use the XamlServices.Parse method, that method can parse the XAML as an object graph as you want.

    Here is a link about XamlServices.Parse method you can refer to:
    http://msdn.microsoft.com/en-us/library/system.xaml.xamlservices.parse(VS.100).aspx

    Also, here is a link about how to load XAML at running time, the situation is fimiliar with yours, you can refer to:
    http://www.mostlydevelopers.com/blog/post/2009/01/15/load-xaml-at-runtime.aspx

    The code in this link using VB. But I think you can translate it into C# easily, here is the link about the translator.
    http://www.carlosag.net/Tools/CodeTranslator/


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 21, 2011 3:19 AM
  • Vin Jin

     

       Thanks for the response.  I'm reading in WPF 3D XAML, so I would like to display the parsed XAML as a 3D figure in a window.  I'm assuming .Net has some method call(s) for this?

    Thanks

     

    [Tim]

     

    Tuesday, June 21, 2011 10:56 PM
  • Hi Tbenner,

    I am not sure whether you have read the link carefully. But based on your description, as the link says you can use the XamlReader class to read the XAML as ab onject, then you can convert the object as the Type you want.

    Here is the link about XamlReader:
    http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlreader.aspx

    In the link there is a samle as follows:

    Button readerLoadButton = (Button)XamlReader.Load(xmlReader);
    I am not sure what is your type of 3D fugure, but you can do as the above code.

    Then you can add the type into your application and to display just as the button to show in your application. If any misunderstanding, please feel free let me know. Thanks.

     


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Sheldon _Xiao Wednesday, June 22, 2011 12:20 PM
    • Marked as answer by Aspen VJ Monday, June 27, 2011 2:38 AM
    Wednesday, June 22, 2011 5:53 AM