Welcome to WindowsClient.net | Sign in | Join

Rob Relyea - XAMLified

WPF, Silverlight and XAML

Syndication

Sponsors





  • advertise here
BindingFinder-Utility (and sample code) to find all Bindings in a XAML UI project

I wrote a sample to show a coworker how to find all Bindings in a project. BindingFinder uses msbuild apis, xaml apis (from .NET + XAML Toolkit).

See http://robrelyea.com/demos/BindingFinder for links to the code and any future updates.

Example output of this command line app:

C:\Users\rrelyea\Documents\Visual Studio 2010\Projects\Bugz\Bugz>bindingfinder Bugz.csproj
FileName: App.xaml 0 bindings found
FileName: DataDesign.xaml
  Binding Path=IterationPath located at (30,18)-(30,18)
  Binding Path=Source located at (29,15)-(29,15)
  Binding Path=Area4 located at (26,17)-(26,17)
  Binding Path=Area3 located at (25,17)-(25,17)
  Binding Path=ID located at (24,14)-(24,14)
  Binding Path=Title located at (21,14)-(21,14)
FileName: MainWindow.xaml
  Binding Path=PUTriage located at (33,32)-(33,32)
  Binding Path=IterationPath located at (32,32)-(32,32)
  Binding Path=Source located at (31,32)-(31,32)
  Binding Path=Area5 located at (28,32)-(28,32)
  Binding Path=Area4 located at (27,32)-(27,32)
  Binding Path=Area3 located at (26,32)-(26,32)
  Binding Path=ID located at (24,28)-(24,28)
  Binding Path=Title located at (22,32)-(22,32)

 Here is the code that uses the XamlDom to find all bindings:

            //Iterate through each XAML file in the project
            foreach (string xamlFilePath in projectData.XamlFiles)
            {
                Console.Write("FileName: " + xamlFilePath);
                FileInfo xamlFile = projectData.GetFileInfoFromRelativePath(xamlFilePath);

                //Load XAML file into a XamlDom (which ships in the XamlToolkit - http://code.msdn.microsoft.com/xaml)
                XamlDomObject rootObject = XamlDomServices.Load(xamlFile.FullName, schemaContext);

                //Do a LinQ query on the XamlNodes in the XamlDom to find all {Bindings}
                foreach (XamlDomObject objectNode in
                    from bindings in rootObject.DescendantsAndSelf(bindingXamlType)
                    select bindings)
                {
                    GenerateOutputForObjectNode(objectNode);
                }

            }
Published Saturday, August 21, 2010 11:23 AM by Rob_Relyea

Comments

# re: BindingFinder-Utility (and sample code) to find all Bindings in a XAML UI project@ Sunday, August 22, 2010 11:00 AM

@JoeWhite-

Yes, (start line, start offset) - (end line, end offset).

When the Binding is in an attribute "{Binding Foo}", the location of the start and end is the same. This is due to the XmlReader just giving us that data. XamlXmlReader uses XmlReader...

Thanks, Rob

# Dew Drop – August 23, 2010 | Alvin Ashcraft's Morning Dew@ Monday, August 23, 2010 7:19 AM

Pingback from  Dew Drop – August 23, 2010 | Alvin Ashcraft's Morning Dew

# re: BindingFinder-Utility (and sample code) to find all Bindings in a XAML UI project@ Monday, August 23, 2010 1:50 PM

Might be interesting to look for good practices in Bindings.

Perhaps even check for this: code.logos.com/.../detecting_bindings_that_should_be_onetime.html

MIght be better to make it a XAMLFxCop rule...

-Rob

# Twitted by guercheLE@ Tuesday, August 24, 2010 9:21 PM

Pingback from  Twitted by guercheLE

# Find all Bindings in a XAML UI project | WPF Dev@ Thursday, August 26, 2010 4:07 PM

Pingback from  Find all Bindings in a XAML UI project | WPF Dev

# Microsoft XAML Toolkit | Nick On Topic@ Wednesday, October 13, 2010 6:07 AM

Pingback from  Microsoft XAML Toolkit | Nick On Topic

# Static analysis of Silverlight XAML: Basic concepts@ Thursday, December 23, 2010 7:47 PM

Silverlight has APIs that support quite a variety of client-side APIs. But one area where the API is

# Static analysis of Silverlight XAML: Basic concepts - BooleanBase@ Friday, December 24, 2010 2:42 AM

Pingback from  Static analysis of Silverlight XAML: Basic concepts - BooleanBase

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Page view counter