Esempio n. 1
0
        public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null)
        {
            View holder          = null;
            var  currentActivity = PlatformExtensions.CurrentActivity;

            if (currentActivity != null)
            {
                var selector = currentActivity.GetBindingMemberValue(AttachedMembersDesign.Activity.SnackbarViewSelector);
                holder = selector == null
                    ? currentActivity.GetBindingMemberValue(AttachedMembersDesign.Activity.SnackbarView)
                    : selector(content, position, context);
            }
            if (holder == null)
            {
                return(_defaultPresenter.ShowAsync(content, duration, position, context));
            }

            var templateSelector = currentActivity.GetBindingMemberValue(AttachedMembersDesign.Activity.SnackbarTemplateSelector);
            var toastImpl        = new ToastImpl();

            if (_threadManager.IsUiThread)
            {
                ShowInternal(toastImpl, templateSelector, holder, content, duration, position, context);
            }
            else
            {
                _threadManager.InvokeOnUiThreadAsync(() => ShowInternal(toastImpl, templateSelector, holder, content, duration, position, context), OperationPriority.High);
            }
            return(toastImpl);
        }
        /// <summary>
        ///     Displays a message box that has a message, title bar caption, button, and icon; and that accepts a default message
        ///     box result and returns a result.
        /// </summary>
        /// <param name="messageBoxText">A <see cref="T:System.String" /> that specifies the text to display.</param>
        /// <param name="caption">A <see cref="T:System.String" /> that specifies the title bar caption to display.</param>
        /// <param name="button">A <see cref="MessageButton" /> value that specifies which button or buttons to display.</param>
        /// <param name="icon">A <see cref="MessageImage" /> value that specifies the icon to display.</param>
        /// <param name="defaultResult">
        ///     A <see cref="MessageResult" /> value that specifies the default result of the message
        ///     box.
        /// </param>
        /// <param name="context">The specified context.</param>
        /// <returns>A <see cref="MessageResult" /> value that specifies which message box button is clicked by the user.</returns>
        public Task <MessageResult> ShowAsync(string messageBoxText, string caption = "",
                                              MessageButton button        = MessageButton.Ok, MessageImage icon      = MessageImage.None,
                                              MessageResult defaultResult = MessageResult.None, IDataContext context = null)
        {
            bool             success;
            MessageBoxButton buttons = ConvertMessageBoxButtons(button, out success);

            Should.BeSupported(success, "The MessageBoxAdapter doesn't support {0} value", button);

            if (_threadManager.IsUiThread)
            {
                MessageBoxResult result = MessageBox.Show(messageBoxText, caption, buttons,
                                                          ConvertMessageBoxImages(icon),
                                                          ConvertMessageBoxResults(defaultResult));
                return(ToolkitExtensions.FromResult(ConvertMessageBoxResult(result)));
            }
            var tcs = new TaskCompletionSource <MessageResult>();

            _threadManager.InvokeOnUiThreadAsync(() =>
            {
                MessageBoxResult result = MessageBox.Show(messageBoxText, caption, buttons,
                                                          ConvertMessageBoxImages(icon), ConvertMessageBoxResults(defaultResult));
                tcs.SetResult(ConvertMessageBoxResult(result));
            });
            return(tcs.Task);
        }
Esempio n. 3
0
        /// <summary>
        ///     Transitions the control between two states.
        /// </summary>
        /// <returns>
        ///     true if the control successfully transitioned to the new state; otherwise, false.
        /// </returns>
        /// <param name="view">The view to transition between states. </param>
        /// <param name="stateName">The state to transition to.</param>
        /// <param name="useTransitions">true to use a VisualTransition to transition between states; otherwise, false.</param>
        /// <param name="context">The specified context.</param>
        public Task <bool> GoToStateAsync(IView view, string stateName, bool useTransitions, IDataContext context)
        {
            Should.NotBeNull(view, "view");
#if WPF
            var control = view.GetUnderlyingView() as FrameworkElement;
#else
            var control = view.GetUnderlyingView() as Control;
#endif
            if (control == null)
            {
                return(Empty.FalseTask);
            }
            var tcs = new TaskCompletionSource <bool>();
            _threadManager.InvokeOnUiThreadAsync(() =>
            {
#if WPF
                var result = System.Windows.VisualStateManager.GoToState(control, stateName, useTransitions);
#elif !NETFX_CORE && !WINDOWSCOMMON
                var result = System.Windows.VisualStateManager.GoToState(control, stateName, useTransitions);
#else
                var result = Windows.UI.Xaml.VisualStateManager.GoToState(control, stateName, useTransitions);
#endif
                tcs.SetResult(result);
            });
            return(tcs.Task);
        }
Esempio n. 4
0
        public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null)
        {
            var toastImpl = new ToastImpl();

            if (_threadManager.IsUiThread)
            {
                toastImpl.CloseAction = ShowInternal(content, duration, position, context, toastImpl.Tcs);
            }
            else
            {
                _threadManager.InvokeOnUiThreadAsync(() => toastImpl.CloseAction = ShowInternal(content, duration, position, context, toastImpl.Tcs));
            }
            return(toastImpl);
        }
Esempio n. 5
0
        public Task <MessageResult> ShowAsync(string messageBoxText, string caption = "",
                                              MessageButton button        = MessageButton.Ok, MessageImage icon      = MessageImage.None,
                                              MessageResult defaultResult = MessageResult.None, IDataContext context = null)
        {
            if (_threadManager.IsUiThread)
            {
                return(ToolkitExtensions.FromResult(ShowMessage(messageBoxText, caption, button, icon, defaultResult)));
            }
            var tcs = new TaskCompletionSource <MessageResult>();

            _threadManager.InvokeOnUiThreadAsync(
                () => tcs.SetResult(ShowMessage(messageBoxText, caption, button, icon, defaultResult)));
            return(tcs.Task);
        }
Esempio n. 6
0
        /// <summary>
        ///     Shows the specified message.
        /// </summary>
        public Task ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null)
        {
            var tcs = new TaskCompletionSource <object>();

            if (_threadManager.IsUiThread)
            {
                ShowInternal(content, duration, position, context, tcs);
            }
            else
            {
                _threadManager.InvokeOnUiThreadAsync(() => ShowInternal(content, duration, position, context, tcs));
            }
            return(tcs.Task);
        }
Esempio n. 7
0
        public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom,
                                IDataContext context = null)
        {
            var toast = new ToastImpl();

            if (_threadManager.IsUiThread)
            {
                Show(content, duration, position, context, toast);
            }
            else
            {
                _threadManager.InvokeOnUiThreadAsync(() => Show(content, duration, position, context, toast));
            }
            return(toast);
        }
        public Task <MessageResult> ShowAsync(string message, string caption = "",
                                              MessageButton button           = MessageButton.Ok, MessageImage icon      = MessageImage.None,
                                              MessageResult defaultResult    = MessageResult.None, IDataContext context = null)
        {
            var tcs = new TaskCompletionSource <MessageResult>();

            if (_threadManager.IsUiThread)
            {
                ShowMessage(message, caption, button, tcs);
            }
            else
            {
                _threadManager.InvokeOnUiThreadAsync(() => ShowMessage(message, caption, button, tcs));
            }
            return(tcs.Task);
        }
Esempio n. 9
0
        public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom,
                                IDataContext context = null)
        {
            var toast = new ToastWrapper(new TaskCompletionSource <object>(), _threadManager);

            if (_threadManager.IsUiThread)
            {
                ShowInternal(content, duration, position, context, toast);
            }
            else
            {
                _threadManager.InvokeOnUiThreadAsync(() => ShowInternal(content, duration, position, context, toast),
                                                     OperationPriority.High);
            }
            return(toast);
        }
 private void CloseableViewModelOnClosed(object sender, ViewModelClosedEventArgs args)
 {
     if (_ignoreCloseFromViewModel)
     {
         return;
     }
     _threadManager.InvokeOnUiThreadAsync(() =>
     {
         try
         {
             _closedFromViewModel = true;
             if (NavigationService.CanGoBack)
             {
                 NavigationService.GoBack();
             }
         }
         finally
         {
             _closedFromViewModel = false;
         }
     });
 }