• Prism研究之一: Silverlight HelloWorld Demo


    1.首先建一个Silverlight项目:HelloWorld.Silverlight.PrismSample

    2.在解决方案中add新项目Silverlight类库HelloWorld.Silverlight.HelloWorldModule

     在引用中添加

      Microsoft.Practices.Composite.dll
     Microsoft.Practices.Composite.Presentation.dll

    HelloWorldModule.cs代码
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Practices.Composite.Modularity;
    using Microsoft.Practices.Composite.Regions;
    using HelloWorld.Silverlight.HelloWorldModule.Views;

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



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



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

    }
    }
    }

    3.在HelloWorld.Silverlight.HelloWorldModule 项目中add一个文件夹Views

    views 中的HelloWorldView.xaml代码
    <UserControl x:Class="HelloWorld.Silverlight.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>

    以下在HelloWorld.Silverlight.PrismSample项目中

    在引用中添加下面5个的引用

        Microsoft.Practices.Composite.dll
     Microsoft.Practices.Composite.Presentation.dll
     Microsoft.Practices.Composite.UnityExtensions.dll
     Microsoft.Practices.ServiceLocation.dll
     Microsoft.Practices.Unity.dll

    再添加项目引用HelloWorld.Silverlight.HelloWorldModule

    4.MainPage 改成Shell

    Shell.xaml
    <UserControl x:Class="HelloWorld.Silverlight.PrismSample.Shell"
    xmlns
    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:Regions
    ="clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;assembly=Microsoft.Practices.Composite.Presentation"
    xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d
    ="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable
    ="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
    <ItemsControl Name="MainRegion" Regions:RegionManager.RegionName="MainRegion"/>
    </Grid>
    </UserControl>
    App.xaml.cs代码
    private void Application_Startup(object sender, StartupEventArgs e)
    {
    //this.RootVisual = new Shell();

    var bootStrapper
    = new Bootstrapper();

    bootStrapper.Run();

    }

    5.添加类Bootstrapper.cs

    Bootstrapper.cs代码
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Practices.Composite.UnityExtensions;
    using Microsoft.Practices.Composite.Modularity;

    namespace HelloWorld.Silverlight.PrismSample
    {
    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(HelloWorld.Silverlight.HelloWorldModule.HelloWorldModule));
    return catalog;
    }
    }
    }
  • 相关阅读:
    Asp.Net细节性问题精萃(转)
    开发OFFICE插件总结(转)
    校内网开心网数据同步引发的讨论(转)
    C++指针探讨 (三) 成员函数指针 (转)
    C++指针探讨 (二) 函数指针 (转)
    【原创】编程获取PE文件信息的方法(转)
    为.net开发者提供的一份关于存储过程的评论(转)
    C++指针探讨 (一)数据指针 (转)
    如何批量修改PPT字体、大小、颜色(转)
    搜索引擎里的爱人(转)
  • 原文地址:https://www.cnblogs.com/honeymoon/p/1732103.html
Copyright © 2020-2023  润新知