ViewHandler.ValidateContainerView(Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Validates that containerView is a container type this handler supports, throwing if it is not.
protected:
virtual void ValidateContainerView(System::Object ^ containerView);
protected virtual void ValidateContainerView(object containerView);
abstract member ValidateContainerView : obj -> unit
override this.ValidateContainerView : obj -> unit
Protected Overridable Sub ValidateContainerView (containerView As Object)
Parameters
- containerView
- Object
The candidate container view. This is never null.
Exceptions
Thrown by overrides when containerView is not supported.
Remarks
Called by SetContainerView(Object) before the value is stored. Override this when a derived handler shadows ContainerView with a more specific type, so that an unsupported container is rejected where the mistake is made instead of surfacing later as an InvalidCastException from the shadowing getter.
The .NET MAUI iOS and Mac Catalyst handlers use this to require a WrapperView. An external backend that shadows ContainerView with its own wrapper type should do the same.
Note that containerView is typed as the platform view type of the target framework, which is Object on the non-platform (neutral) build. An override must therefore match that type rather than the backend's own platform type, and test the concrete wrapper type with a pattern match.
public new MyWrapperView? ContainerView => (MyWrapperView?)base.ContainerView;
// The parameter type is the target framework's platform view type - 'object' on the neutral build.
protected override void ValidateContainerView(object containerView)
{
if (containerView is not MyWrapperView)
{
throw new ArgumentException(
$"The container view must be a {nameof(MyWrapperView)}.",
nameof(containerView));
}
base.ValidateContainerView(containerView);
}