Solved

XAML Reader

Posted on 2014-02-19
10
288 Views
Last Modified: 2014-02-24
Is there a way to programmatically access the XAML text of the currently running page in .net?
0
Comment
Question by:Dodsworth
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39873331
Are you trying to do something with the XAML, or debugging?

XAML Spy
http://xamlspy.com/
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39873554
I need to access it from code behind.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39873842
I don't know of a way, other than System.Windows.Markup.XamlReader.

May I ask what your use case is for reading the XAML?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39873898
Hi  Dodsworth;

When the project using XAML such as WPF and Silverlight the XAML gets compiled and becomes a BAML, Binary Application Markup Language. This is done so that the application does not get slowed down when running the code to compile it. So the simple answer is no. But XAML represents user defined controls and these controls if given a x:Name can be accessed through code.

I hope that helps.
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 39874695
What in particular are you trying to get at from the code-behind?
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39876172
I'd like to get the complete PhoneApplicationPage XAML.
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39876219
OK so I have found a means to read the XAML, but with one problem...  I can only view the compiled XAML.

My requirement is to read the current 'running' XAML, after elements have been added to the page in code behind.  Don't know how or where this is managed :(
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 39876891
There is no XAML for elements that are added in code-behind.
The definition of an element in XAML has the same effect as the creation of an element in code-behind and adding it as a child of some existing element: they both add the element to the Visual Tree.
Are you trying to examine the current content?
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39876912
Yes
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39876948
Maybe this will help you. VisualTreeHelper Class, At the bottom of the page you will find a code snippet on how to visit all the nodes in the tree.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Simple Injector with Web Service 4 41
Modal Popup Extender control 1 20
write xml in vb.net 2 24
.NET 2008 VB and C# 6 28
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question