locked
Loading XAML graphics dynamically RRS feed

  • Question

  • Hi,
    I've got a lot of XAML (vector) graphic elements.
    I would like 1 graphic to be loaded dynamically, according to conditions met in the program.
    In clear, I would like "GraphA" to be displayed if user has chosen "A", "GraphB" displayed if user has chosen "B"...etc

    My question is:
    How can I get those XAML elements saved in a library, or resource, as it is possible for bitmap and sounds for instance. Preventing them to be downloaded, but included in the project.
    And then, how can I load 1 graphic in a canvas, and replace it by another (in the same canvas) according to users choice?

    Thanks a lot for your help!
    Friday, February 24, 2012 8:41 PM

Answers

All replies

  • Hi jmdeb,

    As for your first concern, you could save your object as xaml content, and then you could use XamlWriter to save and load it by XamlReader, refer to this document in MSDN,

    http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlreader.aspx

    http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlwriter.aspx

    there is a save/load method, you could use it to get your object.

    As for your second concern, you could replace your graphic by add/remove method of canvas.

    Canvas.Children.Add();
    Canvas.Children.RemoveAt();

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Pengpeng Song Wednesday, February 29, 2012 2:39 PM
    • Marked as answer by Sheldon _Xiao Tuesday, March 6, 2012 6:11 AM
    Wednesday, February 29, 2012 5:03 AM
  • Hi jmdeb,
     
    I am marking your issue as "Answered", if you have new findings about your issue, please let me know.
     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 6, 2012 6:11 AM