첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ StackPanelRegionAdapter.cs

using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;

using Prism.Regions;

namespace TestProject
{
    /// <summary>
    /// 스택 패널 영역 어댑터
    /// </summary>
    public class StackPanelRegionAdapter : RegionAdapterBase<StackPanel>
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - StackPanelRegionAdapter(regionBehaviorFactory)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="regionBehaviorFactory">영역 BEHAVIOR 팩토리 인터페이스</param>
        public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory)
        {
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 채택하기 - Adapt(region, regionTarget)

        /// <summary>
        /// 채택하기
        /// </summary>
        /// <param name="region">영역</param>
        /// <param name="regionTarget">영역 타겟</param>
        protected override void Adapt(IRegion region, StackPanel regionTarget)
        {
            region.Views.CollectionChanged += (s, e) =>
            {
                if(e.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach(FrameworkElement element in e.NewItems)
                    {
                        regionTarget.Children.Add(element);
                    }
                }
            };
        }

        #endregion
        #region 영역 생성하기 - CreateRegion()

        /// <summary>
        /// 영역 생성하기
        /// </summary>
        /// <returns>영역 인터페이스</returns>
        protected override IRegion CreateRegion()
        {
            return new AllActiveRegion();
        }

        #endregion
    }
}

 

728x90

 

▶ MainWindow.xaml

<Window x:Class="TestProject.Views.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:prism="http://prismlibrary.com/"
    Width="800"
    Height="600"
    Title="RegionAdapterBase&lt;T&gt; 클래스 : 커스텀 영역 어댑터 생성하기">
    <Grid>
        <StackPanel prism:RegionManager.RegionName="ContentRegion" />
    </Grid>
</Window>

 

300x250

 

▶ MainWindow.xaml.cs

using System.Windows;

namespace TestProject.Views
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
        }

        #endregion
    }
}

 

▶ MainApplication.xaml

<prism:PrismApplication x:Class="TestProject.MainApplication"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:prism="http://prismlibrary.com/">
</prism:PrismApplication>

 

▶ MainApplication.xaml.cs

using System.Windows;
using System.Windows.Controls;

using Prism.Ioc;
using Prism.Regions;
using Prism.Unity;

using TestProject.Views;

namespace TestProject
{
    /// <summary>
    /// 메인 애플리케이션
    /// </summary>
    public partial class MainApplication : PrismApplication
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 쉘 생성하기 - CreateShell()

        /// <summary>
        /// 쉘 생성하기
        /// </summary>
        /// <returns>쉘</returns>
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        #endregion
        #region 타입 등록하기 - RegisterTypes(containerRegistry)

        /// <summary>
        /// 타입 등록하기
        /// </summary>
        /// <param name="containerRegistry">컨테이너 레지스트리 인터페이스</param>
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
        }

        #endregion
        #region 영역 어댑터 매핑 구성하기 - ConfigureRegionAdapterMappings(regionAdapterMappings)

        /// <summary>
        /// 영역 어댑터 매핑 구성하기
        /// </summary>
        /// <param name="regionAdapterMappings">영업 어댑터 매핑</param>
        protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
        {
            base.ConfigureRegionAdapterMappings(regionAdapterMappings);

            regionAdapterMappings.RegisterMapping(typeof(StackPanel), Container.Resolve<StackPanelRegionAdapter>());
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요