Esempio n. 1
0
        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);
        }
 public SinglePathObserver([NotNull] object source, [NotNull] IBindingPath path, bool ignoreAttachedMembers)
     : base(source, path)
 {
     Should.BeSupported(path.IsSingle, "The SinglePathObserver supports only single path members.");
     _ignoreAttachedMembers = ignoreAttachedMembers;
     _ref = ServiceProvider.WeakReferenceFactory(this);
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="SinglePathObserver" /> class.
 /// </summary>
 public SinglePathObserver([NotNull] object source, [NotNull] IBindingPath path, bool ignoreAttachedMembers)
     : base(source, path)
 {
     Should.BeSupported(path.IsSingle, "The SinglePathObserver supports only single path members.");
     _ignoreAttachedMembers = ignoreAttachedMembers;
     _pathMembers           = UnsetBindingPathMembers.Instance;
     Update();
 }
 public MultiPathObserver([NotNull] object source, [NotNull] IBindingPath path, bool ignoreAttachedMembers)
     : base(source, path)
 {
     Should.BeSupported(!path.IsEmpty, "The MultiPathObserver doesn't support the empty path members.");
     _listeners             = new List <IDisposable>(path.Parts.Count - 1);
     _ignoreAttachedMembers = ignoreAttachedMembers;
     _lastMemberListener    = new LastMemberListener(ServiceProvider.WeakReferenceFactory(this));
 }
 public SinglePathObserver([NotNull] object source, [NotNull] IBindingPath path, bool ignoreAttachedMembers, bool hasStablePath, bool observable, bool optional)
     : base(source, path)
 {
     Should.BeSupported(path.IsSingle, "The SinglePathObserver supports only single path members.");
     _ignoreAttachedMembers = ignoreAttachedMembers;
     _ref           = ToolkitServiceProvider.WeakReferenceFactory(this);
     _hasStablePath = hasStablePath;
     _observable    = observable;
     _optional      = optional;
 }
Esempio n. 6
0
 static CompiledExpressionInvoker()
 {
     ProxyMethod                 = typeof(CompiledExpressionInvoker).GetMethodEx("InvokeDynamicMethod", MemberFlags.Instance | MemberFlags.NonPublic);
     DataContextParameter        = Expression.Parameter(typeof(IDataContext), "dataContext");
     BindingMemberGetValueMethod = typeof(IBindingMemberInfo).GetMethodEx("GetValue", new[] { typeof(object), typeof(object[]) });
     GetMemberValueDynamicMethod = typeof(CompiledExpressionInvoker).GetMethodEx("GetMemberValueDynamic", MemberFlags.Static | MemberFlags.NonPublic);
     EmptyObjectArrayExpression  = Expression.Constant(Empty.Array <object>(), typeof(object[]));
     Should.BeSupported(BindingMemberGetValueMethod != null, "BindingMemberGetValueMethod");
     Should.BeSupported(GetMemberValueDynamicMethod != null, "GetMemberValueDynamicMethod");
 }
 private void OnViewModelsChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (_clearing)
     {
         _clearing = false;
     }
     else
     {
         Should.BeSupported(e.Action != NotifyCollectionChangedAction.Reset, "The MultiViewModel.ItemsSource doesn't support Clear method.");
     }
     OnViewModelsChanged(e.NewItems, e.OldItems, e.OldStartingIndex);
 }
Esempio n. 8
0
        private bool GoBackInternal()
        {
            Should.BeSupported(CanGoBack, "Go back is not supported in current state.");
            bool animated;
            var  viewModel = CurrentContent?.DataContext() as IViewModel;

            if (viewModel == null || !viewModel.Settings.State.TryGetData(NavigationConstants.UseAnimations, out animated))
            {
                animated = UseAnimations;
            }
            return(NavigationController.PopViewController(animated) != null);
        }
Esempio n. 9
0
 static CompiledExpressionInvoker()
 {
     StringConcatMethod          = typeof(string).GetMethodEx(nameof(string.Concat), new[] { typeof(object), typeof(object) }, MemberFlags.Public | MemberFlags.Static);
     ProxyMethod                 = typeof(CompiledExpressionInvoker).GetMethodEx(nameof(InvokeDynamicMethod), MemberFlags.Instance | MemberFlags.Public);
     DataContextParameter        = Expression.Parameter(typeof(IDataContext), "dataContext");
     BindingMemberGetValueMethod = typeof(IBindingMemberInfo).GetMethodEx(nameof(IBindingMemberInfo.GetValue), new[] { typeof(object), typeof(object[]) }, MemberFlags.Public | MemberFlags.Instance);
     GetMemberValueDynamicMethod = typeof(CompiledExpressionInvoker).GetMethodEx(nameof(GetMemberValueDynamic), MemberFlags.Static | MemberFlags.Public);
     GetIndexValueDynamicMethod  = typeof(CompiledExpressionInvoker).GetMethodEx(nameof(GetIndexValueDynamic), MemberFlags.Static | MemberFlags.Public);
     InvokeMemberDynamicMethod   = typeof(CompiledExpressionInvoker).GetMethodEx(nameof(InvokeMemberDynamic), MemberFlags.Static | MemberFlags.Public);
     EqualsMethod                = typeof(object).GetMethodEx(nameof(Equals), MemberFlags.Public | MemberFlags.Static);
     EmptyObjectArrayExpression  = Expression.Constant(Empty.Array <object>(), typeof(object[]));
     Should.BeSupported(BindingMemberGetValueMethod != null, nameof(BindingMemberGetValueMethod));
     Should.BeSupported(GetMemberValueDynamicMethod != null, nameof(GetMemberValueDynamicMethod));
     Should.BeSupported(GetIndexValueDynamicMethod != null, nameof(GetIndexValueDynamicMethod));
     Should.BeSupported(InvokeMemberDynamicMethod != null, nameof(InvokeMemberDynamicMethod));
     Should.BeSupported(EqualsMethod != null, nameof(EqualsMethod));
 }
        private void ShowMessage(string messageBoxText, string caption, MessageButton button, MessageImage icon,
                                 MessageResult defaultResult,
                                 TaskCompletionSource <MessageResult> tcs)
        {
#if XAMARIN_FORMS
            var activity = global::Xamarin.Forms.Forms.Context;
#else
            var activity = PlatformExtensions.CurrentActivity as IActivityView;
#endif
            Should.BeSupported(activity != null, "The current top activity is null.");
            AlertDialog.Builder builder = new AlertDialog.Builder((Context)activity)
                                          .SetTitle(caption)
                                          .SetMessage(messageBoxText)
                                          .SetCancelable(false);
            switch (button)
            {
            case MessageButton.Ok:
                builder.SetPositiveButton(GetButtonText(MessageResult.Ok),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Ok));
                break;

            case MessageButton.OkCancel:
                builder.SetPositiveButton(GetButtonText(MessageResult.Ok),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Ok));
                builder.SetNegativeButton(GetButtonText(MessageResult.Cancel),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Cancel));
                break;

            case MessageButton.YesNo:
                builder.SetPositiveButton(GetButtonText(MessageResult.Yes),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Yes));
                builder.SetNegativeButton(GetButtonText(MessageResult.No),
                                          (sender, args) => tcs.TrySetResult(MessageResult.No));
                break;

            case MessageButton.YesNoCancel:
                builder.SetPositiveButton(GetButtonText(MessageResult.Yes),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Yes));
                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    builder.SetNegativeButton(GetButtonText(MessageResult.No),
                                              (sender, args) => tcs.TrySetResult(MessageResult.No));
                    builder.SetNeutralButton(GetButtonText(MessageResult.Cancel),
                                             (sender, args) => tcs.TrySetResult(MessageResult.Cancel));
                }
                else
                {
                    builder.SetNeutralButton(GetButtonText(MessageResult.No),
                                             (sender, args) => tcs.TrySetResult(MessageResult.No));
                    builder.SetNegativeButton(GetButtonText(MessageResult.Cancel),
                                              (sender, args) => tcs.TrySetResult(MessageResult.Cancel));
                }
                break;

            case MessageButton.AbortRetryIgnore:
                builder.SetPositiveButton(GetButtonText(MessageResult.Abort),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Abort));
                builder.SetNeutralButton(GetButtonText(MessageResult.Retry),
                                         (sender, args) => tcs.TrySetResult(MessageResult.Retry));
                builder.SetNegativeButton(GetButtonText(MessageResult.Ignore),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Ignore));
                break;

            case MessageButton.RetryCancel:
                builder.SetPositiveButton(GetButtonText(MessageResult.Retry),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Retry));
                builder.SetNegativeButton(GetButtonText(MessageResult.Cancel),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Cancel));
                break;

            default:
                throw new ArgumentOutOfRangeException("button");
            }
            int?drawable = GetIconResource(icon);
            if (drawable != null)
            {
                builder.SetIcon(drawable.Value);
            }
            AlertDialog dialog = builder.Create();
#if !XAMARIN_FORMS
            EventHandler <Activity, EventArgs> handler = null;
            handler = (sender, args) =>
            {
                ((IActivityView)sender).Mediator.Destroyed -= handler;
                tcs.TrySetResult(defaultResult);
            };
            activity.Mediator.Destroyed += handler;
#endif
            dialog.Show();
        }
Esempio n. 11
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EmptyPathObserver" /> class.
 /// </summary>
 public EmptyPathObserver([NotNull] object source, [NotNull] IBindingPath path)
     : base(source, path)
 {
     Should.BeSupported(path.IsEmpty, "The EmptyPathObserver supports only empty path members.");
     _members = new EmptyBindingPathMembers(this);
 }
 private bool GoBackInternal()
 {
     Should.BeSupported(CanGoBack, "Go back is not supported in current state.");
     return(NavigationController.PopViewControllerAnimated(true) != null);
 }
Esempio n. 13
0
 public EmptyPathObserver([NotNull] object source, [NotNull] IBindingPath path)
     : base(source, path)
 {
     Should.BeSupported(path.IsEmpty, "The EmptyPathObserver supports only empty path members.");
     _members = new EmptyBindingPathMembers(ServiceProvider.WeakReferenceFactory(this));
 }
Esempio n. 14
0
        /// <summary>
        ///     Occurs when any workspace view model is changed.
        /// </summary>
        private void OnViewModelsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            Should.BeSupported(e.Action != NotifyCollectionChangedAction.Reset, "The IMultiViewModel.ItemsSource doesn't support Clear method.");
            if (e.NewItems != null && e.NewItems.Count != 0)
            {
                for (int index = 0; index < e.NewItems.Count; index++)
                {
                    var viewModel = (IViewModel)e.NewItems[index];
                    // ReSharper disable once NotResolvedInText
                    Should.NotBeNull(viewModel, "newItem");
                    var closeableViewModel = viewModel as ICloseableViewModel;
                    if (closeableViewModel != null)
                    {
                        closeableViewModel.Closed += _weakEventHandler;
                    }
                    var selectable = viewModel as ISelectable;
                    if (selectable != null)
                    {
                        selectable.PropertyChanged += _propertyChangedWeakEventHandler;
                    }
                    OnViewModelAddedEvent(viewModel);
                }
            }

            if (e.OldItems != null && e.OldItems.Count != 0)
            {
                for (int index = 0; index < e.OldItems.Count; index++)
                {
                    var viewModel = (IViewModel)e.OldItems[index];
                    TrySetPreviousValue(viewModel, e.OldStartingIndex + index);

                    var closeableViewModel = viewModel as ICloseableViewModel;
                    if (closeableViewModel != null)
                    {
                        closeableViewModel.Closed -= _weakEventHandler;
                    }

                    var navigableViewModel = viewModel as INavigableViewModel;
                    if (navigableViewModel != null)
                    {
                        navigableViewModel.OnNavigatedFrom(new NavigationContext(NavigationMode.Back, viewModel,
                                                                                 SelectedItem, this));
                    }

                    var selectable = viewModel as ISelectable;
                    if (selectable != null)
                    {
                        if (selectable.IsSelected)
                        {
                            selectable.IsSelected = false;
                        }
                        selectable.PropertyChanged -= _propertyChangedWeakEventHandler;
                    }
                    OnViewModelRemovedEvent(viewModel);
                    if (DisposeViewModelOnRemove)
                    {
                        viewModel.Dispose();
                    }
                }
            }
        }
Esempio n. 15
0
        private void ShowMessage(string messageBoxText, string caption, MessageButton button, MessageImage icon,
                                 MessageResult defaultResult,
                                 TaskCompletionSource <MessageResult> tcs)
        {
#if XAMARIN_FORMS
            var activity = Xamarin.Forms.Forms.Context;
#else
            var activity = _navigationProvider.CurrentContent as IActivityView;
#endif
            Should.BeSupported(activity != null, "The current top activity is null.");
            AlertDialog.Builder builder = new AlertDialog.Builder((Context)activity)
                                          .SetTitle(caption)
                                          .SetMessage(messageBoxText)
                                          .SetCancelable(false);
            switch (button)
            {
            case MessageButton.Ok:
                builder.SetPositiveButton(GetButtonText(MessageResult.Ok),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Ok));
                break;

            case MessageButton.OkCancel:
                builder.SetPositiveButton(GetButtonText(MessageResult.Ok),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Ok));
                builder.SetNegativeButton(GetButtonText(MessageResult.Cancel),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Cancel));
                break;

            case MessageButton.YesNo:
                builder.SetPositiveButton(GetButtonText(MessageResult.Yes),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Yes));
                builder.SetNegativeButton(GetButtonText(MessageResult.No),
                                          (sender, args) => tcs.TrySetResult(MessageResult.No));
                break;

            case MessageButton.YesNoCancel:
                builder.SetPositiveButton(GetButtonText(MessageResult.Yes),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Yes));
                builder.SetNeutralButton(GetButtonText(MessageResult.No),
                                         (sender, args) => tcs.TrySetResult(MessageResult.No));
                builder.SetNegativeButton(GetButtonText(MessageResult.Cancel),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Cancel));
                break;

            case MessageButton.AbortRetryIgnore:
                builder.SetPositiveButton(GetButtonText(MessageResult.Abort),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Abort));
                builder.SetNeutralButton(GetButtonText(MessageResult.Retry),
                                         (sender, args) => tcs.TrySetResult(MessageResult.Retry));
                builder.SetNegativeButton(GetButtonText(MessageResult.Ignore),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Ignore));
                break;

            case MessageButton.RetryCancel:
                builder.SetPositiveButton(GetButtonText(MessageResult.Retry),
                                          (sender, args) => tcs.TrySetResult(MessageResult.Retry));
                builder.SetNeutralButton(GetButtonText(MessageResult.Cancel),
                                         (sender, args) => tcs.TrySetResult(MessageResult.Cancel));
                break;

            default:
                throw new ArgumentOutOfRangeException("button");
            }
            int?drawable = GetIconResource(icon);
            if (drawable != null)
            {
                builder.SetIcon(drawable.Value);
            }
            AlertDialog dialog = builder.Create();
#if !XAMARIN_FORMS
            activity.Destroyed += (sender, args) => tcs.TrySetResult(defaultResult);
#endif
            dialog.Show();
        }