처리기

.NET 다중 플랫폼 앱 UI(.NET MAUI)는 데이터를 표시하고, 작업을 시작하고, 활동을 나타내고, 컬렉션을 표시하고, 데이터를 선택하는 데 사용할 수 있는 플랫폼 간 컨트롤 컬렉션을 제공합니다. 각 컨트롤에는 컨트롤을 추상화하는 인터페이스 표현이 있습니다. 이러한 인터페이스를 구현하는 플랫폼 간 컨트롤을 가상 보기라고 합니다. 처리기는 이러한 가상 보기를 네이티브 뷰라고 하는 각 플랫폼의 컨트롤에 매핑합니다. 또한 처리기는 기본 네이티브 뷰를 인스턴스화하고 플랫폼 간 제어 API를 네이티브 뷰 API에 매핑합니다. 예를 들어 iOS에서 처리기는 .NET MAUI Button 를 iOS UIButton에 매핑합니다. Android에서는 다음 Button 항목에 AppCompatButton매핑됩니다.

Button handler architecture.

.NET MAUI 처리기는 컨트롤 관련 인터페이스(예: IButton 에 대해 Button)를 통해 액세스됩니다. 이렇게 하면 플랫폼 간 컨트롤이 해당 처리기를 참조해야 하고 처리기가 플랫폼 간 컨트롤을 참조하지 않아도 됩니다.

각 처리기 클래스는 해당 속성을 통해 플랫폼 간 컨트롤에 대한 네이티브 뷰를 노출합니다 PlatformView . 이 속성에 액세스하여 네이티브 뷰 속성을 설정하고, 네이티브 뷰 메서드를 호출하고, 네이티브 뷰 이벤트를 구독할 수 있습니다. 또한 처리기에 의해 구현된 플랫폼 간 컨트롤은 해당 VirtualView 속성을 통해 노출됩니다.

네이티브 뷰를 통해 각 플랫폼에서 구현이 제공되는 플랫폼 간 컨트롤을 만들 때 플랫폼 간 컨트롤 API를 네이티브 뷰 API에 매핑하는 처리기를 구현해야 합니다. 자세한 내용은 처리기를 사용하여 사용자 지정 컨트롤 만들기를 참조 하세요.

처리기를 사용자 지정하여 컨트롤의 API를 통해 가능한 사용자 지정 외에 기존 플랫폼 간 컨트롤의 모양과 동작을 보강할 수도 있습니다. 이 처리기 사용자 지정은 플랫폼 간 컨트롤에 대한 네이티브 보기를 수정합니다. 처리기는 전역이며 컨트롤에 대한 처리기를 사용자 지정하면 앱에서 동일한 형식의 모든 컨트롤이 사용자 지정됩니다. 자세한 내용은 처리기를 사용하여 .NET MAUI 컨트롤 사용자 지정을 참조 하세요.

매퍼

.NET MAUI 처리기의 주요 개념은 매퍼입니다. 각 처리기는 일반적으로 플랫폼 간 컨트롤의 API를 네이티브 뷰의 API에 매핑하는 속성 매퍼 및 때로는 명령 매퍼를 제공합니다.

속성 매퍼는 플랫폼 간 컨트롤에서 속성 변경이 발생할 때 수행할 작업을 정의합니다. Dictionary 플랫폼 간 컨트롤의 속성을 연결된 작업에 매핑하는 것입니다. 그런 다음 각 플랫폼 처리기는 네이티브 뷰 API를 조작하는 Actions의 구현을 제공합니다. 이렇게 하면 플랫폼 간 컨트롤에 속성이 설정되면 기본 네이티브 뷰가 필요에 따라 업데이트됩니다.

명령 매퍼플랫폼 간 컨트롤이 네이티브 뷰에 명령을 보낼 때 수행할 작업을 정의합니다. 속성 매퍼와 비슷하지만 추가 데이터를 전달할 수 있습니다. 이 컨텍스트의 명령은 구현을 ICommand 의미하지 않습니다. 대신 명령은 명령일 뿐이며 필요에 따라 기본 보기로 전송되는 데이터입니다. 명령 매퍼는 Dictionary 플랫폼 간 컨트롤의 명령을 연결된 작업에 매핑하는 것입니다. 그런 다음 각 처리기는 네이티브 뷰 API를 조작하는 Actions의 구현을 제공합니다. 이렇게 하면 플랫폼 간 컨트롤이 명령을 네이티브 보기로 보낼 때 필요에 따라 네이티브 뷰가 업데이트됩니다. 예를 들어 스크롤될 ScrollViewHandlerScrollView 명령 매퍼를 사용하여 스크롤 위치 인수를 허용하는 작업을 호출합니다. 그런 다음 작업은 기본 네이티브 뷰에 해당 위치로 스크롤하도록 지시합니다.

네이티브 보기를 업데이트하기 위해 매퍼를 사용하면 네이티브 뷰를 플랫폼 간 컨트롤에서 분리할 수 있다는 장점이 있습니다. 이렇게 하면 네이티브 뷰가 플랫폼 간 제어 이벤트를 구독하고 구독을 취소할 필요가 없습니다. 또한 서브클래싱 없이 매퍼를 수정할 수 있으므로 쉽게 사용자 지정할 수 있습니다.

처리기 수명 주기

모든 처리기 기반 .NET MAUI 컨트롤은 두 개의 처리기 수명 주기 이벤트를 지원합니다.

  • HandlerChanging 는 플랫폼 간 컨트롤에 대한 새 처리기를 만들 때와 플랫폼 간 컨트롤에서 기존 처리기를 제거하려고 할 때 발생합니다. 이 이벤트 NewHandler 와 함께 제공되는 개체에는 HandlerChangingEventArgs 형식IElementHandler의 속성이 있습니다OldHandler. 속성이 NewHandler 아닌 null경우 이벤트는 플랫폼 간 컨트롤에 대한 새 처리기를 만들 예정임을 나타냅니다. 속성이 OldHandler 아닌 null경우 이벤트는 기존 네이티브 컨트롤이 플랫폼 간 컨트롤에서 제거될 예정임을 나타내므로 네이티브 이벤트는 배선을 해제하고 다른 클린 수행되어야 합니다.
  • HandlerChanged 는 플랫폼 간 컨트롤에 대한 처리기를 만든 후에 발생합니다. 이 이벤트는 플랫폼 간 컨트롤을 구현하는 네이티브 컨트롤을 사용할 수 있으며 플랫폼 간 컨트롤에 설정된 모든 속성 값이 네이티브 컨트롤에 적용되었음을 나타냅니다.

참고 항목

이벤트는 HandlerChanging 이벤트 전에 플랫폼 간 컨트롤에서 발생합니다 HandlerChanged .

이러한 이벤트 외에도 각 플랫폼 간 컨트롤에는 이벤트가 발생할 때 HandlerChanging 호출되는 재정의 가능한 OnHandlerChanging 메서드와 OnHandlerChanged 이벤트가 발생할 때 HandlerChanged 호출되는 메서드도 있습니다.

처리기 보기

다음 표에서는 .NET MAUI에서 뷰를 구현하는 형식을 나열합니다.

보기 인터페이스 처리기 속성 매퍼 명령 매퍼
ActivityIndicator IActivityIndicator ActivityIndicatorHandler Mapper CommandMapper
BlazorWebView IBlazorWebView BlazorWebViewHandler BlazorWebViewMapper
Border IBorderView BorderHandler Mapper CommandMapper
BoxView IShapeView, IShape ShapeViewHandler Mapper CommandMapper
Button IButton ButtonHandler ImageButtonMapper, , TextButtonMapperMapper CommandMapper
CarouselView CarouselViewHandler Mapper
Cell CellRenderer Mapper CommandMapper
CheckBox ICheckBox CheckBoxHandler Mapper CommandMapper
CollectionView CollectionViewHandler <Mapper
ContentView IContentView ContentViewHandler Mapper CommandMapper
DatePicker IDatePicker DatePickerHandler Mapper CommandMapper
Editor IEditor EditorHandler Mapper CommandMapper
Ellipse IShape ShapeViewHandler Mapper CommandMapper
Entry IEntry EntryHandler Mapper CommandMapper
EntryCell EntryCellRenderer Mapper CommandMapper
Frame FrameRenderer Mapper CommandMapper
GraphicsView IGraphicsView GraphicsViewHandler Mapper CommandMapper
Image IImage ImageHandler Mapper CommandMapper
ImageButton IImageButton ImageButtonHandler ImageMapper, Mapper
ImageCell ImageCellRenderer Mapper CommandMapper
IndicatorView IIndicatorView IndicatorViewHandler Mapper CommandMapper
Label ILabel LabelHandler Mapper CommandMapper
Line IShape LineHandler Mapper CommandMapper
ListView ListViewRenderer Mapper CommandMapper
Map IMap MapHandler Mapper CommandMapper
Path IShape PathHandler Mapper CommandMapper
Picker IPicker PickerHandler Mapper CommandMapper
Polygon IShape PolygonHandler Mapper CommandMapper
Polyline IShape PolylineHandler Mapper CommandMapper
ProgressBar IProgress ProgressBarHandler Mapper CommandMapper
RadioButton IRadioButton RadioButtonHandler Mapper CommandMapper
Rectangle IShape RectangleHandler Mapper CommandMapper
RefreshView IRefreshView RefreshViewHandler Mapper CommandMapper
RoundRectangle IShape RoundRectangleHandler Mapper CommandMapper
ScrollView IScrollView ScrollViewHandler Mapper CommandMapper
SearchBar ISearchBar SearchBarHandler Mapper CommandMapper
Slider ISlider SliderHandler Mapper CommandMapper
Stepper IStepper StepperHandler Mapper CommandMapper
SwipeView ISwipeView SwipeViewHandler Mapper CommandMapper
Switch ISwitch SwitchHandler Mapper CommandMapper
SwitchCell SwitchCellRenderer Mapper CommandMapper
TableView TableViewRenderer Mapper CommandMapper
TextCell TextCellRenderer Mapper CommandMapper
TimePicker ITimePicker TimePickerHandler Mapper CommandMapper
ViewCell ViewCellRenderer Mapper CommandMapper
WebView IWebView WebViewHandler Mapper CommandMapper

페이지 처리기

다음 표에서는 .NET MAUI에서 페이지를 구현하는 형식을 나열합니다.

페이지 Android 처리기 iOS/Mac Catalyst Handler Windows 처리기 속성 매퍼 명령 매퍼
ContentPage PageHandler PageHandler PageHandler Mapper CommandMapper
FlyoutPage FlyoutViewHandler 전화FlyoutPageRenderer FlyoutViewHandler Mapper CommandMapper
NavigationPage NavigationViewHandler NavigationRenderer NavigationViewHandler Mapper CommandMapper
TabbedPage TabbedViewHandler TabbedRenderer TabbedViewHandler Mapper CommandMapper
Shell ShellHandler ShellRenderer ShellRenderer Mapper CommandMapper