Welcome to WindowsClient.net | Sign in | Join

Rob Relyea - XAMLified

WPF, Silverlight and XAML

XamlPadSample Step 1f-alternateViews, app.xaml & assembly loading

3 major features added to XamlPadSample today! Including Alternate Views, which has not been done in any XamlPad or XamlDesigner that I’m aware of. (link to previous posts/overview & sample code available via XamlPadSample)

App.xaml Support for {StaticResource}

View pane now shows result of {StaticResource} or {DynamicResource} resolution of resources from app.xaml. Shown loading Welcome.xaml from Family.Show v3.

image

 

Assembly Loading

XAML files which include uses of classes from local: or other custom types in project class libraries now load. Shown loading PersonInfo.xaml from Family.Show v3. (note, XamlPadSample doesn’t ever call build on your project/solution.)

image

 

Alternate Views

The AlternateViews feature enables you to put something more useful in the “white blank pane” of a non-UI rooted XAML file.

Below you can see a crude UI representation of BlackResources (from Family.Show v3) showing many brushes, DataTemplates, Styles that were defined in a ResourceDictionary.

The sample also contains a simple visual representation for App.xaml and XamlPadConfig.

image

 

Detailed notes from Backlog.txt in sample code:

---------------------------------------------
2010/01/30 - posted v1f - Alternate View, app.xaml, and assembly loading
---------------------------------------------
Implemented: {StaticResource foo} will now resolve to resources in the current page or in the ApplicationDefinition xaml file (matched Blend/Cider feature)
Implemented: Assemblies from a project will now be loaded (matches Blend/Cider/XamlCruncher feature)
Implemented: Provided the start of a mechanism to provide alternate views for non-visual root elements. Lots of potential here...

XamlPadHelpers project
•ResourceProxy.cs (NEW)
◦Added ResourceProxy, a ContentControl - to hold a pointer to the App.Resources for a project. We inject this element during the parse as the real root of the tree we are building.
  This enables {StaticResources } that we parse to find resources delared in App.xaml or in a merged dictionary as well.
•AssemblyData.cs
◦In v1e, I had plumbed this class to find the right assembly. Now there is a Load() method a property of type Assembly to store the loaded assembly.
•ProjectData.cs
◦Added a ContentProperty for <ProjectData> - the AssemblyReferences property. Doesn't change the functionality of Pad.config.xaml, just the conciseness.
◦Added an ApplicationResources property which will load the corresponding app.xaml and grab the .Resources property from it.
•View.cs (NEW)
◦New class to track a Type->TemplateUri mapping. This is effectively a Dictionary, but notice the [DictionaryKeyProperty("Type")] on the class, which enables avoiding x:Key in the XAML.
  This is the same (now v4 public feature) that Style, ControlTemplate, and DataTemplate use to avoid needing a x:Key by default.
•XamlEngine.cs
◦LoadObjectsForDesign now has an appResources property, and will inject a new ResourceProxy(appResources) as the root object in the tree if appResources is not null.
◦new LoadXamlDocument routine that will use CreateReader() and LoadObjectsForDesign()
◦new LoadXamlDocumentWIthAppResources routine that will use CreateReader() and LoadObjectsForDesign(), and it will pass in appResources into LoadObjectsForDesign if we know
  of the app.xaml
•XamlPad.xaml.cs
◦XamlText_TextChanged() enhanced to attempt to load each assembly of a project before parse.
◦XamlText_TextChanged() enhanced to wire in alternate Views (via XamlPadConfig.Views mappings) for any non-UI root objects displayed in XamlPad.
  TODO: wouldn't mine cleaning up this code...I think I changed error experience badly...
•XamlPadConfig.cs
◦Added the Views property for the alternate views feature.
•XamlPadHelpers.datatemplates.xaml (NEW)
◦Added several DataTemplates that provide basic visual representations for object graphs that have the following roots: Application, ResourceDictionary, XamlPadConfig

Pad project
•MainWindow.xaml.cs
◦Added 3 default Views to plug into the default Pad.config.xaml (for AlternateViews feature)

Published Saturday, January 30, 2010 2:40 AM by Rob_Relyea

Comments

# Dew Drop &#8211; January 30, 2010 | Alvin Ashcraft&#039;s Morning Dew@ Saturday, January 30, 2010 9:12 AM

Pingback from  Dew Drop &#8211; January 30, 2010 | Alvin Ashcraft&#039;s Morning Dew

Leave a Comment

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