internal static void SetContentView([NotNull] this ViewGroup frameLayout, [NotNull] object content,
                                            [NotNull] FragmentTransaction transaction,
                                            [NotNull] Action <ViewGroup, Fragment, FragmentTransaction> updateAction)
        {
            Should.NotBeNull(frameLayout, nameof(frameLayout));
            var view = content as View;

            if (view == null)
            {
                var fragment = (Fragment)content;
                AndroidToolkitExtensions.ValidateViewIdFragment(frameLayout, fragment);
                updateAction(frameLayout, fragment, transaction);
            }
            else
            {
                if (frameLayout.ChildCount == 1 && frameLayout.GetChildAt(0) == view)
                {
                    return;
                }
                frameLayout.RemoveAllViews();
                frameLayout.AddView(view);
            }
        }
        public bool SetContent(object view, object content)
        {
            var targetView = view as ViewGroup;

            if (targetView == null)
            {
                return(false);
            }
            if (content == null)
            {
                FragmentManager fragmentManager = targetView.GetFragmentManager();
                Fragment        oldFragment     = fragmentManager?.FindFragmentById(targetView.Id);
                if (oldFragment != null && !fragmentManager.IsDestroyed)
                {
                    BeginTransaction(fragmentManager, targetView, null)
                    .Remove(oldFragment)
                    .CommitAllowingStateLoss();
                    fragmentManager.ExecutePendingTransactions();
                    return(true);
                }
                return(false);
            }
            var fragment = content as Fragment;

            if (fragment == null)
            {
                return(false);
            }
            AndroidToolkitExtensions.ValidateViewIdFragment(targetView, fragment);
            FragmentManager manager = targetView.GetFragmentManager();

            if (manager == null)
            {
                return(false);
            }
            FragmentTransaction transaction = BeginTransaction(manager, targetView, fragment);
            var addToBackStack = targetView.GetBindingMemberValue(AttachedMembers.ViewGroup.AddToBackStack);

            if (addToBackStack && fragment.Arguments != null)
            {
                addToBackStack = !fragment.Arguments.GetBoolean(AddedToBackStackKey);
            }

            if (fragment.IsDetached)
            {
                transaction.Attach(fragment);
            }
            else
            {
                if (addToBackStack)
                {
                    if (fragment.Arguments == null)
                    {
                        fragment.Arguments = new Bundle();
                    }
                    fragment.Arguments.PutBoolean(AddedToBackStackKey, true);
                }
                transaction.Replace(targetView.Id, fragment);
            }
            if (addToBackStack)
            {
                transaction.AddToBackStack(null);
            }

            transaction.Commit();
            manager.ExecutePendingTransactions();
            return(true);
        }