[MAUI] ViewHandler - InvalidOperationException이 발생합니다. (Context cannot be null here)

Custom Controls이 포함된 Page를 열 때 InvalidOperationExceptiond : Context cannot be null here 이 발생합니다.

// ViewHandlerOf.Android code...
public Context Context => MauiContext?.Context ?? throw new InvalidOperationException($"Context cannot be null here");

// runtime error : Navigating to `Custom Controls`
System.InvalidOperationException: Context cannot be null here

Custom Controls에서 발생하는 Exception입니다.

ViewHandler throw new InvalidOperationException 코드 링크입니다.


질문입니다.

Handler가 없어서 발생하는 문제 일까요?

=> Ex) class ViewHandler<CustomControls, TPlatformView: null>
CustomControls could not recognize the platform

Context가 어떤 경우에 Null이 될 수 있을까요?



+++

  • Handler를 생성하는 방법은? (예제를 봤을 때 무엇을 상속 받아서 구현해야 하는지 모르겠네요)
  • null 처리는 어떻게 할까요?
// Example
// ref: https://devblogs.microsoft.com/dotnet/customizing-dotnet-maui-controls/
// by Pedro Jesus
if (control.Handler is null || control.Handler.PlatformView is null)
{
    // Workaround for when this executes the Handler and PlatformView is null
    control.HandlerChanged += OnHandlerChanged;
    return;
}

샘플 링크

2개의 좋아요

stack Overflow 답변입니다.

private readonly SKCanvasView _canvas;

public SampleBorder()
{
    _canvas = new SKCanvasView; // SDK 지원 문제입니다.
    InputTransparent = true; // ??? 확인 중입니다.
}
  • 원인 1 : SKCanvasViewSDK 8.0을 지원하지 않습니다. => SDK 7.0으로 변경
  • 원인 2 : InputTransparent를 변경할 때 발생합니다.
    2023.11.20 현재 해결 방법을 찾고 있습니다.
2개의 좋아요