public void Complete(TResult result)
        {
            //HRESULT hr = S_OK;

            //IFCEXPECT(m_isInitialized);
            //AssertInvariants();

            //if (m_flyoutState == FlyoutState::Open)
            //{
            //	// If the flyout is not already closed or closing, then we're being called
            //	// because the user accepted a selection, and the flyout will be closed shortly
            //	// by PickerFlyoutBase::OnConfirmedImpl
            //	m_flyoutState = FlyoutState::Closing;
            //}

            if (m_flyoutState == FlyoutState.Open)
            {
                m_flyoutState = FlyoutState.Closing;
            }


            //if (m_spCurrentOperation)
            //{
            if (m_spCurrentOperation != null)
            {
                //	wrl::ComPtr<wf::IAsyncInfo> spAsyncInfo;
                //	wf::AsyncStatus asyncStatus = wf::AsyncStatus::Started;

                //	// If an operation is deferred, then it is not associated with the current
                //	// open/close cycle of this flyout, and we should not complete it unless it
                //	// has been cancelled.
                //	IFC(m_spCurrentOperation.As(&spAsyncInfo));
                //	IFC(spAsyncInfo->get_Status(&asyncStatus));
                var asyncStatus = m_spCurrentOperation.Status;
                if (!m_isShowAtForCurrentOperationDeferred || asyncStatus == AsyncStatus.Canceled)
                {
                    AssertCompleteOperationPreconditions();

                    //		// nulls out m_spCurrentOperation. This is important in the case of rentrancy;
                    //		// the consumer's CompleteOperation handler may trigger another call to Start,
                    //		// in which case we want Start to be able to return a deferred operation
                    //		// rather than failing.
                    //		wrl::ComPtr<xaml_controls::IPickerFlyoutAsyncOperation<TResult>> spCurrentOperation;
                    //		spCurrentOperation.Swap(m_spCurrentOperation);
                    m_isShowAtForCurrentOperationDeferred = false;
                    m_tpTargetForDeferredShowAt           = null;
                    m_spCurrentOperation.CompleteOperation(result);
                    m_spCurrentOperation = null;
                    //		IFC(spCurrentOperation->CompleteOperation(result));
                }
                //}


                //Cleanup:
                //RRETURN(hr);
            }

            AssertInvariants();
        }
        public IAsyncOperation <TResult> Start(FrameworkElement pTarget)
        {
            //HRESULT hr = S_OK;
            PickerFlyoutAsyncOperation <TResult> spAsyncOp;

            //// Validation
            //IFCEXPECT(m_isInitialized);
            //AssertInvariants();
            //if (m_spCurrentOperation)
            //{
            //	ROERROR_LOOKUP(E_ASYNC_OPERATION_NOT_STARTED, ERR_ASYNC_ALREADY_IN_PROGRESS);
            //}
            if (m_spCurrentOperation != null)
            {
                throw new InvalidOperationException("Async operation in progress.");
            }
            //if (m_flyoutState == FlyoutState::Open)
            //{
            //	ROERROR_LOOKUP(E_ASYNC_OPERATION_NOT_STARTED, ERR_FLYOUT_ALREADY_OPEN);
            //}

            //IFC((wrl::MakeAndInitialize<xaml_controls::PickerFlyoutAsyncOperation<TResult, OpName>>(&spAsyncOp)));
            spAsyncOp = new PickerFlyoutAsyncOperation <TResult>();
            //IFC(spAsyncOp->StartOperation(m_pAssociatedFlyoutNoRef));
            spAsyncOp.StartOperation(m_pAssociatedFlyoutNoRef);

            //pTarget = m_tpTargetForDeferredShowAt;
            //IFC(SetPtrValue(m_tpTargetForDeferredShowAt, pTarget));

            // UNO-TODO: TEMPORARY DISABLE THIS FEATURE
            // m_isShowAtForCurrentOperationDeferred = true;

            //if (m_flyoutState == FlyoutState::Closed)
            //{
            //	IFC(BeginAttemptStartDeferredOperation());
            //}

            if (m_flyoutState == FlyoutState.Closed)
            {
                // The flyout is currently closed so we can try to show now, but we have to treat this
                // as a deferred op anyway and show asynchronously in case we're being called from the
                // closed event handler, as FlyoutBase may swallow a synchronous call to ShowAt in that case.

                BeginAttemptStartDeferredOperation();
            }

            //m_spCurrentOperation = static_cast<xaml_controls::IPickerFlyoutAsyncOperation<TResult>*>(spAsyncOp.Get());
            m_spCurrentOperation = spAsyncOp;
            //IFC(spAsyncOp.CopyTo(ppOperation));

            AssertInvariants();

            //Cleanup:
            //RRETURN(hr);

            return(spAsyncOp);
        }