- SofaAdditionalExamples_-_Step_by_Step.zip
- Examples
- Step by step SofaComponization
- 0. Original CSWPFMasterDetailBinding
- 1. From Application To Component
- 2. From Simple Component to sub-Components
- 3. About Perspectives
- External dependencies
- log4net.dll
- Mef.Codeplex
- System.ComponentModel.Composition.Codeplex.dll
- System.ComponentModel.Composition.Registration.dll
- System.Reflection.Context.dll
- Prism.Mef_Codeplex
- Microsoft.Practices.Prism.dll
- Microsoft.Practices.Prism.Interactivity.dll
- Microsoft.Practices.Prism.MefExtensions.dll
- Microsoft.Practices.Prism.UnityExtensions.dll
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Unity.dll
- Microsoft.Practices.Unity.Interception.dll
- WPFToolkit.dll
- Libraries
- ExternalFrameworks.dll
- Sofa.Commons.dll
- Sofa.Component.dll
- Sofa.Container.dll
- Sofa.Themes.dll
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Sofa.Container;
using Sofa.Commons;
using System.Reflection;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel;
using System.ComponentModel.Composition;
namespace CSWPFMasterDetailBinding
{
/// <summary>
/// Interaction logic for HAPSofacontainer.xaml
/// </summary>
[Export("Sofa.Examples.SofaComponization.SofaBasicContainer_ViewContract", typeof(UserControl))]
[ExportMetadata("ProductName", "CSWPFMasterDetailBinding")]
[ExportMetadata("AvalonContentType", "DocumentContent")]
[ExportMetadata("AvalonPaneGroup", "RightSide")]
[ExportMetadata("IfExists_DefaultValue", "DoNotUseIt")]
[ExportMetadata("ImageURI", "")]
[ExportMetadata("Label", "CSWPFMasterDetailBinding")]
[ExportMetadata("DockId", 0)]
public partial class MainComponent : UserControl, IBaseContainer, IPartImportsSatisfiedNotification
{
//Import sub-components of HAPSofacontainer
[ImportMany("Sofa.Examples.SofaComponization.MainComponent_ViewContract", AllowRecomposition = true)]
ExportFactory <UserControl, ISofaComponent_Metadata>[] _views = null;
//IBaseContainer implementation
public SofaContainer SofaContainer
{
get { return sofaContainer; }
set { sofaContainer = value; }
}
//Not used, required by IBaseContainer
public SofaMenu SofaMenu
{
get { return null; }
set { }
}
public MainComponent()
{
InitializeComponent();
}
public void OnImportsSatisfied()
{
foreach (var view in _views)
{
CmpModel cmp = sofaContainer.RegisterComponent(view);
}
}
//==================== Sofa specific code ==========================================
//MainComponent is a SofaContainer AND also a Sofa Component
//The SofaComponent containing this application
private SofaComponent thisSofaComponent;
public SofaComponent ThisSofaComponent
{
get { return thisSofaComponent; }
set { thisSofaComponent = value; }
}
//The Container (SofaBasicContainer) of this SofaComponent
private IBaseContainer container;
public IBaseContainer Container
{
get { return container; }
set
{
container = value;
Container.SofaContainer.SofaCommon += SofaCommonEventHandler;
}
}
public void SofaCommonEventHandler(object sender, SofaEventArgs e)
{
if (e.TargetGUID == ThisSofaComponent.GUID)
{
if (e.EventType == "PostOpen")
{
//Open the 2 components
sofaContainer.OpenComponent("CustomerList");
sofaContainer.OpenComponent("OrderList");
//Find the CustomerListComponent and get listViewCustomers as DataContext for this OderListComponent
SofaComponent customerComponent = null;
SofaComponent orderComponent = null;
try
{
customerComponent = SofaContainer.SofaComponentList.Single(c => c.ProductName == "CustomerList");
orderComponent = SofaContainer.SofaComponentList.Single(c => c.ProductName == "OrderList");
}
catch { }
if (customerComponent != null && orderComponent != null)
orderComponent.UserControl.DataContext = ((CustomerListComponent)customerComponent.UserControl).listViewCustomers;
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.