Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms;

namespace Xamarin.CommunityToolkit.UI.Views.Internals
{
Expand All @@ -9,9 +8,7 @@ namespace Xamarin.CommunityToolkit.UI.Views.Internals
/// <typeparam name="TControl">The type of the control that this template will be used for</typeparam>
public abstract class BaseTemplatedView<TControl> : TemplatedView where TControl : View, new()
{
TControl? control;

protected TControl Control => control ?? throw new NullReferenceException();
protected TControl? Control { get; private set; }

/// <summary>
/// Constructor of <see cref="BaseTemplatedView{TControl}" />
Expand All @@ -23,15 +20,15 @@ protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();

if (control != null)
if (Control != null)
Control.BindingContext = BindingContext;
}

protected override void OnChildAdded(Element child)
{
if (control == null && child is TControl content)
if (Control == null && child is TControl control)
{
control = content;
Control = control;
OnControlInitialized(Control);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,18 +637,18 @@ void RemoveChild(View view)
void RaiseMenuIfNeeded(View? menuView)
{
if (menuView != null && GetMenuAppearanceType(menuView) == SideMenuAppearanceType.SlideIn)
Control.RaiseChild(menuView);
Control?.RaiseChild(menuView);
}

void OnLayoutChanged(object? sender, EventArgs e)
{
if (mainView == null)
return;

using (Control.Batch())
using (Control?.Batch())
{
Control.RaiseChild(mainView);
Control.RaiseChild(overlayView);
Control?.RaiseChild(mainView);
Control?.RaiseChild(overlayView);

RaiseMenuIfNeeded(leftMenu);
RaiseMenuIfNeeded(rightMenu);
Expand Down