With the overwhelming number of things to learn, and resources you have to sift through (to determine their value), I would have to say that the following Channel 9 webcast is a gem if you are starting to work with WPF. XBAP for the most part is underdocumented - this reveals much of it and it should raise your interest as well as your understanding.
http://channel9.msdn.com/posts/Charles/WPF-XBAP/
Imagine being able to share user controls between your Windows and Browser applications - the only differing component is the view and it's code behind (with the Presenter, controllers and model being shared by both platforms)....
While assisting jjalexrayer with his Load module in shell in WPF Browser Application issue I discovered that it is possible and practical to share controls between platforms with WPF. Using the CompositeWPF Commanding solution I was able to reuse all of the business rules and logic in a browser application with minimal coding.
I used the Commanding.sln and added a new WpfBrowserApp project (source code attached below). The CommandingBootStrapper.cs file follows:
using System.ComponentModel;
using System.Windows;
using Commanding.Modules.Order;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.UnityExtensions;
using WpfBrowserApp;
namespace Commanding
{
class CommandingBootstrapper : UnityBootstrapper
{
Page1 shell = null;
public CommandingBootstrapper(Page1 page)
{
shell = page;
}
protected override DependencyObject CreateShell()
{
Container.BuildUp<Page1>(shell);
return shell;
}
protected override IModuleEnumerator GetModuleEnumerator()
{
return new StaticModuleEnumerator().AddModule(typeof(OrderModule));
}
}
}
Page1 Code behind looks as follows (didn't need the Container - just wanted to see if it would be there - it was :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using Commanding;
namespace WpfBrowserApp
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
private IUnityContainer _container;
[Dependency]
public IUnityContainer Container
{
set { _container = value; }
}
public Page1()
{
InitializeComponent();
CommandingBootstrapper bootstrapper =
new CommandingBootstrapper(this);
bootstrapper.Run();
}
}
}
I grabbed the XAML from Command projects Shell (minus the Window.Background elements) so that the CommandingBootStrapper wouldn't puke - it needs the GlobalCommandsRegion and MainRegion. I was pretty surprised to find the Page1 XBAP code ran exactly as the Shell WPF!
<Page x:Class="WpfBrowserApp.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/CompositeWPF"
Title="Page1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" Margin="10,0,10,0">
<ItemsControl cal:RegionManager.RegionName="GlobalCommandsRegion" />
</StackPanel>
<Border Grid.Row="2" CornerRadius="4,4,4,4" BorderBrush="#193441" Background="#FCFFF5" BorderThickness="2,2,2,2" Margin="10,0,10,10" Padding="5">
<StackPanel>
<ItemsControl cal:RegionManager.RegionName="MainRegion" />
</StackPanel>
</Border>
<Label HorizontalAlignment="Left" Margin="155,5,0,0" Width="Auto" Content="QuickStart" FontWeight="Normal" Foreground="#FF373737" FontSize="24" FontFamily="Corbel"/>
<Label HorizontalAlignment="Left" Margin="10,5,0,0" Width="Auto" Content="Commanding" FontWeight="Bold" Foreground="#FF373737" FontSize="24" FontFamily="Corbel"/>
<Separator Margin="0,0,0,0" VerticalAlignment="Bottom" Height="10" BorderBrush="#193441"/>
</Grid>
</Page>
Walla! I was reusing the WPF application's code in a browser application.
Source code for WpfBrowserApp (above code) WpfBrowserApp.zip (313.91 kb)
Related Codeplex topic Can I develop XBAP application with this framework?
Tags:
unity,
xbap,
webcast
Categories:
CompositeWPF |
WPF