Using WECPOF in runtime

You can use WECPOF in design time ECO projects and in Gaffr.net files.

This article explains how to use it in runtime to deliver finished applications.

It starts out as an ordinary ECO project (create one from the wizard, Create new project Eco project).

You then create your model, update the code, configure your Persistence mapper of choice, set up any remote persistence mapper and synchronization if you want to just as the PDF-tutorials explain, Create or evolve your database, or derive the model from an existing database with the Reverse derive options.

Then add a WPF-Window or a WPF-Page (for browser applications).

Make sure your project references WECPOFLogic, then add a reference to the xaml :

xmlns:wecpof=”clr-namespace:WECPOFLogic;assembly=WECPOFLogic”

And add a MainMenu and a WECPOFWindowEnvironment (this is where the WECPOF windows will be hosted)

Code Snippet
  1. <Window x:Class="WpfApplication1.Window1"
  2.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"  
  5.     xmlns:wecpof="clr-namespace:WECPOFLogic;assembly=WECPOFLogic"
  6.     Title="Window1" Height="314" Width="354">
  7.     <Window.Resources>
  8.         <LinearGradientBrush x:Key="WECPOFWinBackgroundBrush" EndPoint="0,1" StartPoint="0,0">
  9.             <GradientStop Color="#CCC" Offset="0.0" />
  10.             <GradientStop Color="#EEE" Offset="1.0" />
  11.         </LinearGradientBrush>
  12. … cut for clarity…
  13.     </Window.Resources>
  14.     <Grid>
  15.         <Grid.RowDefinitions>
  16.             <RowDefinition Height="22"></RowDefinition>
  17.             <RowDefinition></RowDefinition>
  18.         </Grid.RowDefinitions>
  19.         <Menu Grid.Row="0"  Name="MainMenu">
  20.         </Menu>
  21.         <wecpof:WECPOFWindowEnvironment x:Name="WecpofWinEnv">
  22.  
  23.         </wecpof:WECPOFWindowEnvironment>
  24.     </Grid>
  25. </Window>

In code behind we need to create our ecospace and hook everything up; this is boiler plate code:

Code Snippet
  1. public partial class Window1 : Window
  2. {
  3.   EcoSpace _ecospace;
  4.   MenuHandling _MenuHandling;
  5.   public Window1()
  6.   {
  7.     InitializeComponent();
  8.  
  9.     // Create ecospace or use one that you have
  10.     _ecospace = new EcoProject1.EcoProject1EcoSpace();
  11.     _ecospace.Active = true;
  12.     // Start up the Eco UI dequeuer ; if not set nothing will show
  13.     WPFDequeuer.Active = true;
  14.     // Load viewmodel definitions from embedded resources
  15.     ViewModelDefinitionsInApplication.Init(_ecospace);
  16.  
  17.     // Create a WECPOF menu handling component
  18.     _MenuHandling = new MenuHandling();
  19.  
  20.     // Define where WECPOF should look for styles
  21.     WecpofWinEnv.PathToStyles = Directory.GetCurrentDirectory() + "\\Styles";
  22.     // And to where WECPOF should apply a choosen style
  23.     WecpofWinEnv.ResourceDictionaryTargetForStyles(this);
  24.     // Tell the MenuHandling component where to put the MenuItems. Hand over the list of Actions from ECO, hand over the EcoSpace.
  25.     // Send in the WindowEnvironment defined in xaml, and say in what context should the speed keys be evaluated
  26.     _MenuHandling.InitMainMenu(MainMenu, ViewModelDefinitionsInApplication.GetActionsRuntime(), _ecospace, WecpofWinEnv, this);
  27.     // Let the WECPOF Window environment know about the MenuHandling component
  28.     WecpofWinEnv.InstallMenuHandling(_MenuHandling);
  29.     // Implement the event to implement Quit…
  30.     MenuHandling.OnExit += new EventHandler<EventArgs>(MenuHandling_OnExit);
  31.   }
  32.  
  33.   void MenuHandling_OnExit(object sender, EventArgs e)
  34.   {
  35.     Close();
  36.   }
  37. }

And you are done:

image

This entry was posted in WCF, WECPOF, Xaml. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*