Answered Saving Element as Xaml

  • Thursday, June 11, 2009 1:40 PM
     
     

    Assume there is a workflow “SimpleWorkflow”, which is a sequence of few elements. At some point of time the host decides to save the workflow as XAML:

    SimpleWorkflow wf = new SimpleWorkflow();
    XamlServices.Save(“c:\\temp\\abc.xaml”, wf);

    After saving the XAML file will contain only the root element of SimpleWorfkflow. The question is how to save (not to persist by using of WorkflowProvider) workflow as XAML which will contain all elements?

    Moreover, it would be helpful to provide example which does following:

    el1= new SomeElement()
    SaveToFile(file1, el1)
    el2 = LoadFromSavedXaml(file1);
    Assert.Equals(el1, el2)
    SaveToFile(file2, el2)
    Assert.Equals(file1, file2)

All Replies

  • Thursday, June 11, 2009 2:55 PM
     
     
    Damir,

    It sounds like you want the Xaml serializer to output the internal implementation details of your compiled type "SimpleWorkflow".  In short, you can do that in some cases, but it's possible (if you implement the type in code)  that you return completely different implementations based on some value passed in, that you've expressed completely in imperative code.   Once you have a compiled type, it's a black box and it's body is an implementation detail, so the xaml serializer is not going to return that.

    Now, if you can get to the body of the workflow, you can pass that object hiearchy to the xaml serializer which will then serailize out the full form, but you would also ahve to figure out how to do something with properties, constructor values that are written in code, etc, that will not serialize out.

    matt
    Program Manager -- Modeling Platform and Tools http://blogs.msdn.com/mwinkle
  • Thursday, June 11, 2009 4:43 PM
     
     

    Hi Matt,

    you are right, but this would be nice to have out of the box J
    However, in WF35 we had a possibility to serialize workflow as xaml by using follwong trick in InitializeComponent:

    WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

    using (XmlTextWriter writer = new XmlTextWriter(string.Format(@"XOML\{0}.xoml",
                           this.GetType().Name), Encoding.Unicode))
    {
                                   serializer.Serialize(writer, this);
    }

    How to do this now with WF4?

  • Thursday, June 11, 2009 9:46 PM
    Moderator
     
     
    I dont think there is a way to serialize out the internal implementation of an activity to XAML. I am not even sure how you do that with workflowmarkupserializer in WF 3.5.
    Senior Lead Program Manager, Windows Workflow Foundation http://blogs.msdn.com/kavitak
  • Thursday, June 11, 2009 10:22 PM
     
     
    What does the type definition for SimpleWorkflow look like?  What XAML do you get when you do XamlServices.Save, and what XAML do you expect?

    Daniel Roth
    Program Manager
    ASMX, WCF Metadata
  • Thursday, June 11, 2009 10:55 PM
     
     Answered
    Just root element without of children.