November 2004 - Posts
The last week was a special week for me because we were releasing a new Deklarit upgrade first and second there were our company “Olympic Games” from Thursday to Saturday, our team was playing tennis, basket, soccer, volley, etc after work. So after the Olympic Games (on Sunday) I could not move my body anywhere J so I was watching TV and dedicated to finish a second version of the XAML Viewer.
I added some features and fixes:
- Edit XAML in the viewer with the same syntax coloring, tips, outlining that in the default editor of VS. How you can add an existing editor in a toolwindow? Dr Ex has the answer here.
- Explicit “Text Mode” for the viewer. I mean the viewer can be bound to the buffer of a file or just to text. If you are editing text this is what I called "Text Mode"
- Setup is complete now (you don't need extra commands after install)
- In the first version, when you call to the XAML Viewer for a file, the viewer was bounded to the file, now it is bounded to the buffer of the opened document, so you don’t need to save the file in order to try how the changes affect the output. The text view of viewer is bounded to the same buffer of the document so if you change something in the viewer it is changed in the document.
- In general Refresh is not needed anymore; I’m parsing when the XAML tab page is activated.
- Rob told me that the viewer could not parse some valid files (for example when the XAML file had codebehind). He helped me with a solution for that so that this is working now. Thanks Rob
- Chris Sells suggested add the Visual Tree to the viewer and he pointed to this post that shows how to do the work. I accepted the suggestion and I had implemented this feature in this way:
- I changed the base code in this way:
public static class VisualUtility
public static void GetVisualTreeInfo(Visual element, XmlWriter writer)
if (element == null)
throw new ArgumentNullException("element");
VisualCollection vc = VisualOperations.GetChildren(element);
if (vc != null && vc.Count > 0)
foreach (Visual v in vc)
- The difference is that this code write the visual tree in XML.
- I was thinking in read this XML and show it a tree view (winform), but I’m learning XAML now!! So I decided to use a XSL in order to generate XAML.
When the visual tree tab is selected the XML is generated and after that the visualtree.xsl is applied in order to get a XAML (in a MemoryStream) and then load this XAML in the tab page. (the tab page has a ElementHost in order to show XAML inside a windows form)
I’m not a graphic designer so I hope that somebody modify my initial visualtree.xsl (it is in the installation folder) to get a better XAML for the Visual Tree. Now it is just a XAML Table.
At this time I suppose you know about the CTP for Avalon but may be you didn't install it yet. I have installed the CTP without problems, my installation order was:
- Whidbey beta 1 (this install framework 2.0 beta)
- Windows SP 2 ( because it is required by the CTP)
- Avalon CTP
After install you should go to Chris Anderson blog and check for cool samples.
Chris Anderson point to a tool XamlPad in order to edit and test xaml, I really like it but obviously I'm a VS man so I wanna edit my xaml files in VS (with intellisense, syntax error check, etc the XML editor in VS is really cool) and more I wanna have a viewer for my xaml file in VS.
So I started developing a Xaml Viewer for VS, it is an interesting sample because I had to use XAML controls in Windows Forms, use VSIP for Whidbey, automation, etc. I gotta post something about this later.
Now I gotta post just my first night of work ;)
- Right click in xaml files to call to the viewer.
- Switch from viewer to associated file
- Show errors in output window and task list, so you can go to the line with double click.
- Call the viewer directly from View\Other Windows\Xaml Viewer
- Text to Xaml, sometimes I need to transform just a text fragment, so you can paste the text in the text view and refresh the viewer in order to see the result.
Here some screen shots:
This sample is in Chris Anderson blog
After install the msi run: devenv /setup in the Whidbey command prompt.
Obviously you need CTP installed in order to go.
N. Chaudhry send me a new version of the code that I posted some time ago. He fixes some bugs and add the Rename action for strings, bitmaps, and icons. Thanks Chaudhry !!
Just to said that I did something in this version I added the ability to see different sizes for icon resources.
Before install the resource editor you have to install the Microsoft Interop Assemblies
This editor open .dll and exe files to, so you can extract icons, it is the only feature that the new whidbey resource editor does not have.
Download the editor.
Source Code is included so it is a good sample of how to use some VSIP features like integrate a new editor in VS, use DTE, etc