The FirstFloor.SilverlightSpy.Interop assembly contains the classes that implement the communication channel between the Silverlight application and the Silverlight Spy host. The interop assembly includes a number of classes are useful to the DLR shell.
The FirstFloor.SilverlightSpy.Interop assembly is always available when a Silverlight application is loaded in Silverlight Spy. Silverlight Spy automatically adds the assembly to the XAP package on-the-fly. The assembly does not need to be added at design-time.
For a complete class library reference of the FirstFloor.SilverlightSpy.Interop assembly, see FirstFloor.SilverlightSpy.Interop.
This topic contains the following sections.
The Spy class provide interoperability with the Silverlight Spy host. Use this class to communicate with Silverlight Spy itself. Spy provides access to the current selected UI element and allows for querying the services that manage the interoperability with the Silverlight Spy host.
The following Python sample explores the current settings.
# explore spy from FirstFloor.SilverlightSpy.Interop import * # visuals print 'Root visual: ' + str(Spy.Current.RootVisual.Element) print 'Selected visual: ' + str(Spy.Current.SelectedVisual.Element) # connection manager print 'Connection state: ' + str(Spy.Current.ConnectionManager.ConnectionState) # ruler manager print 'Ruler style: ' + str(Spy.Current.RulerManager.RulerStyle) # service manager table = out.AddTable('Services', 'Service Name', 'Type') for service in Spy.Current.ServiceManager.GetServices(): table.AddRow(service.Name, service.GetType())
DependencyObjectExtensions provides a number of useful members for querying the visual and logical tree of a Silverlight application. DependencyObjectExtensions is modelled after the LINQ to XML API and supports advanced traversal of the visual and logical tree.
The following Python sample demonstrates the use of the Ancestors member to print the collection of ancestors of the current selected UI element.
from System.Windows import * from FirstFloor.SilverlightSpy.Interop import * import itertools elements = Spy.Current.SelectedVisual.Element.Ancestors() for i, element in enumerate(elements): print str(i) + ' ' + element.GetType().Name + ' (' + element.Name + ')'
The DLR shell also includes a Python sample demonstrating the various members of DependencyObjectExtensions.
The XAML writer that is used by Silverlight Spy itself to generate XAML from any UI element can also be used directly in the DLR shell. XamlWriter generates XAML and provides a XamlWriterSettings class to tweak the XAML being generated.
The following Python sample renders the XAML of the visual tree of an entire Silverlight application.
from System.Windows import * from FirstFloor.SilverlightSpy.Interop import * settings = XamlWriterSettings() settings.Mode = TreeViewMode.VisualTree print XamlWriter.GetXaml(Application.Current.RootVisual, settings)