Exemple #1
0
        /// <summary>
        /// Executes the action on the UI thread.
        /// </summary>
        /// <param name="action">The action to execute.</param>
        /// <param name="delay">The delay.</param>
        public static void OnUIThread(this System.Action action, TimeSpan delay)
        {
            if (delay.TotalMilliseconds < 0)
            {
                throw new ArgumentOutOfRangeException("delay", delay, "Value must be positive");
            }

            Execute.OnUIThread(
                delegate
            {
                DispatcherTimer t = new DispatcherTimer();
                t.Interval        = delay;
                t.Tick           += delegate
                {
                    t.Stop();
                    action();
                };
                t.Start();
            });
        }
            void Closing(object sender, CancelEventArgs e)
            {
                if (e.Cancel)
                {
                    return;
                }

                var guard = (IGuardClose)model;

                if (actuallyClosing)
                {
                    actuallyClosing = false;
                    return;
                }

                bool runningAsync = false, shouldEnd = false;

                guard.CanClose(canClose => {
                    Execute.OnUIThread(() => {
                        if (runningAsync && canClose)
                        {
                            actuallyClosing = true;
                            view.Close();
                        }
                        else
                        {
                            e.Cancel = !canClose;
                        }

                        shouldEnd = true;
                    });
                });

                if (shouldEnd)
                {
                    return;
                }

                runningAsync = e.Cancel = true;
            }
Exemple #3
0
 /// <summary>
 ///   Clears the items contained by the collection.
 /// </summary>
 protected override sealed void ClearItems()
 {
     Execute.OnUIThread(ClearItemsBase);
 }
Exemple #4
0
 /// <summary>
 ///   Removes the item at the specified position.
 /// </summary>
 /// <param name = "index">The position used to identify the item to remove.</param>
 protected override sealed void RemoveItem(int index)
 {
     Execute.OnUIThread(() => RemoveItemBase(index));
 }
Exemple #5
0
 /// <summary>
 ///   Sets the item at the specified position.
 /// </summary>
 /// <param name = "index">The index to set the item at.</param>
 /// <param name = "item">The item to set.</param>
 protected override sealed void SetItem(int index, T item)
 {
     Execute.OnUIThread(() => SetItemBase(index, item));
 }
Exemple #6
0
 /// <summary>
 /// Moves the item within the collection.
 /// </summary>
 /// <param name="oldIndex">The old position of the item.</param>
 /// <param name="newIndex">The new position of the item.</param>
 protected sealed override void MoveItem(int oldIndex, int newIndex)
 {
     Execute.OnUIThread(() => MoveItemBase(oldIndex, newIndex));
 }