Lester's WPF\SL Blog

Simple, Easy & Beautiful

Xaml Toolkit: Manipulation of Xaml

Xaml Toolkit: Manipulation of Xaml

Rate This
  • Comments 4

One of the interesting things you could easily do with the Xaml Toolkit is manipulation of Xaml. For example, in the case of XamlPadX, if we copy pasted xaml from a WPF application, it wouldnt render because of events, unknown members and so forth. We would need to extract these members in order to make the xaml render. Using the Xaml Toolkit, its pretty simple.

XamlDomObject rootObject = XamlDomServices.Load("MainWindow.xaml");

foreach (XamlDomObject objectNode in rootObject.DescendantsAndSelf())

{

    delMemberList.Clear();

    if (objectNode.Type.IsUnknown)

    {

        delDomobjList.Add(objectNode);

        continue;

    }

 

    foreach(XamlDomMember member in objectNode.MemberNodes)

        if (member.Member.IsEvent || member.Member.Name.Equals("Class") || member.Member.IsUnknown) delMemberList.Add(member);

    foreach (XamlDomMember delItem in delMemberList) objectNode.RemoveMemberNode(delItem);

}

 

foreach (XamlDomObject delItem in delDomobjList) delItem.Parent.Items.Remove(delItem);

 

XamlDomServices.Save(rootObject, "NewMainWindow.xaml");

 

You could do the above using nodestreams (Link) but for more complicated manipulations, its easier using the Dom especially given that its Linq friendly :)

The project is attached

Share this post

 

Attachment: ConsoleApplication2.zip
  • Does this mean you might consider updating XamlPadX to include this feature?  C'mon!

  • its on my TODO list ... will update when i get some free time :)

  • This is Windows Client Developer roundup #37. The Windows Client Developer Roundup aggregates information

  • This is Windows Client Developer roundup #37. The Windows Client Developer Roundup aggregates information

Page 1 of 1 (4 items)