C#/Prism

[Prism] 시작하기

딸기우유중독 2022. 11. 23. 17:18

 

목차

1.Prism Template Pcak 으로 시작하기


2.Prism Nuget Package 설치로 시작하기

 

1.Prism Template Pack으로 시작하기

Extensions

Prism Template Pack 설치

 

Create Blank App(WPF)

 


Module 등록

 

Create Module(WPF)

프로젝트 모듈 추가

App.xaml.cs
Add Project Reference

 

Dependencies에 Project Module 추가 후

protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            moduleCatalog.AddModule<ModuleAModule>();
            moduleCatalog.AddModule<ModuleBModule>();
        }

위 override 함수에 추가 할 모듈 추가

 


View Discovery방식

 

ModuleA

위 표시영역은 View Discovery방식

즉시 표시되는 아이템(View)에 대해서만 View Discovery방식을 사용.

Views can be created and displayed in regions automatically

Ex) 메뉴아이템, 상태표시줄.. etc


View Navigation방식 (View Injection)

- Views can be created and displayed in regions programmatically

Module.cs

View를 등록

 

ViewModel

Command에서 받은 Parameter값을 참조해서 view를 불러옴.

 

# ModuleA 의 View에서 ModuleB의 View 호출 가능.

EX)

ModuleB 또한 App.xaml.cs에 등록 후

ModuleA의 ViewModel에서 Command명령의 Parameter로 ModuleB의 View이름을 호출.


Navigation 이벤트

 

viewModel

INavigationAware 상속

관련 인터페이스

Navigation간에 이동할때 진입점 및 탈출점에 이벤트 함수 정의가능.

 

Command

Command에서 Navigation View요청시 parameter값 전달 가능.

 

View 진입 할 때

key 값이 id 인 Value Get

 


IEventAggregator

 

Event.cs
eventAggregator

eventAggregator가 작동하려면 publisher와 subscriber가 필요.

 

publish

MainWindow viewModel에서 MessageEvent publish

subscribe

ModuleA 의  ViewBViewmodel에서 MessageEvent Subscribe

 


CanExecuteCommand

 

NavigateCommand.RaiseCanExecuteChanged()
ObservesProperty()
ObservesCanExecute()

# ObservesCanExecute()사용 추천.

 

 


2.Prism Nuget Package 설치로 시작하기

 

Nuget Package

 

Prism.Core

Prism.DryIoc

Prism.Wpf

 

위 3개 패키지 설치

 

App.xaml

StartupUri="MainWindow.xaml" 삭제 및 위 강조 표시로 추가 AND 변경

 

App.xaml.cs

위 강조표시 추가 및 변경.

 

MainWindow.xaml

위 강조 표시 추가

 

MainWindow.xaml
App.xaml.cs

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<MainWindow, MainWindowViewModel>();
        }

위 등록해줘야 MainWindow 랑 MainWindowViewModel 자동 묶기가능. ( View, ViewModel 등록)


모듈 추가

모듈 추가
WPF Class library

 

ModuleA

Class1.cs => ModuleAModule 이름 변경

 

 

 

인터페이스 추가

 

 

Views

ViewModels

IRegionManager 등 추가


ViewA

 

             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"

View에 추가 ViewModel 자동 묶기

 

ModuleAModule.cs

 

View , ViewModel 등록

 

App.xaml.cs

ModuleA 등록

 

 


프리즘 라이브러리

https://github.com/PrismLibrary

 

Prism

Prism has 8 repositories available. Follow their code on GitHub.

github.com

 

 

 

https://kaki104.tistory.com/854

 

Prism Library를 사용하는 개발자를 위한 안내 Part1

2022.11.30 - [WPF .NET] - Prism Library를 사용하는 개발자를 위한 안내 Part6 - TabControl Region Navigation 2022.11.25 - [WPF .NET] - Prism Library를 사용하는 개발자를 위한 안내 Part5 - Region & ContentControl Region Navigation 202

kaki104.tistory.com

 

https://prismlibrary.com/docs/wpf/legacy/Modules.html

 

Modular Application Development Using Prism Library for WPF | Prism

Modular Application Development Using Prism Library for WPF A modular application is an application that is divided into a set of loosely coupled functional units (named modules) that can be integrated into a larger application. A client module encapsulate

prismlibrary.com

 

https://wiki.bananeatomic.fr/wiki/Prism_8#App.config

 

Prism 8 — Banane Atomic

Links Description Fully open source version of Prism including MVVM Commanding: DelegateCommand Messaging: EventAggregator Navigation Dialog services Modularity Dependency injection Prism 8 supports WPF, Xamarin Forms and UNO, but not Silverlight, Windows

wiki.bananeatomic.fr

 

728x90