간단한 모듈등록하기

실버라이트 프로젝트

image

 

이 프로젝트에서는 추가로

image

DLL을 추가해야합니다.

 

Shell.xaml 는 맨처음 실행되는 페이지 입니다.

<UserControl x:Class="HelloWorld.Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Regions="clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;assembly=Microsoft.Practices.Composite.Presentation"
             Width="400" Height="300">
    <ItemsControl Name="MainRegion" Regions:RegionManager.RegionName="MainRegion"/>
</UserControl>

 

Bootstrapper.cs

using System.Windows;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.UnityExtensions;

namespace HelloWorld
{
    public class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            Shell shell = Container.Resolve<Shell>();
            Application.Current.RootVisual = shell;
            return shell;
        }

        protected override IModuleCatalog GetModuleCatalog()
        {
            ModuleCatalog catalog = new ModuleCatalog()
            .AddModule(typeof(HelloWorldModule.HelloWorldModule));
            return catalog;
        }
    }
}

웹프로젝트

image

실버라이트 실행하는 웹페이지(이프로젝트는 크게 의미없습니다 )

 

모듈 프로젝트 CALSilverlightModule.csproj

image

모듈 프로젝트는 (추가로 Microsoft.Practices.Composite 참조해야합니다).

 

모듈프로젝트에서 아래의 코드를 삽입합니다.

HelloWorldModule.cs

using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;

namespace HelloWorldModule
{
    public class HelloWorldModule : IModule
    {
        private readonly IRegionManager regionManager;

        public HelloWorldModule(IRegionManager regionManager)
        {
            this.regionManager = regionManager;
        }

        public void Initialize()
        {
            regionManager.RegisterViewWithRegion("MainRegion", typeof(Views.HelloWorldView));
        }

    }
}

HelloWorldView.xaml

<UserControl x:Class="HelloWorldModule.Views.HelloWorldView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Grid x:Name="LayoutRoot" Background="White">
            <TextBlock Text="Hello World" Foreground="Green" 
HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Calibri" FontSize="24" 
FontWeight="Bold"></TextBlock>
    </Grid>
</UserControl>

+ Recent posts