Figuring out Silverlight namespaces and assemblies
Often when you find examples of Silverlight code on the web it may only contain a snippet of code rather than the full set needed to make it work. This causes me immense frustration when I am trying to work out what namespace and/or assembly declaration to use at the top of the xaml file.
For example, take the foll开发者_JS百科owing snippet (which shows how to add a list of items as a static resource)
<UserControl.Resources>
<controls:ObjectCollection x:Key="SampleData">
<sys:String>User 1</sys:String>
<sys:String>User 2</sys:String>
<sys:String>User 3</sys:String>
</controls:ObjectCollection>
</UserControl.Resources>
How is it possible for me to determine what namespace and assembly this guy used as the "controls" alias???
What I usually do is:
- Try to add the element to my Xaml, Resharper will help me here if the class is within a referenced assembly. - Search the documentation for the class name. Silverlight sdk doc and then the Toolkit doc.In this case, in SL3, the ObjectCollection class is within the Toolkit:
Namespace: System.Windows.ControlsAssembly: System.Windows.Controls.Toolkit (in System.Windows.Controls.Toolkit.dll)
精彩评论