public MagickImageControl()
        {
            InitializeComponent();

            BusyStack           = new BusyStack();
            BusyStack.OnChanged = (hasItems) => IsBusy = hasItems;
        }
Example #2
0
        // TODO fiure out a way to call this async and still maintain order
        // maybe blocking collection + cancellationtokensource
        private void UpdateDataContext()
        {
            if (Content == null || !IsSelected || GetDataContext == null)
            {
                return;
            }

            // while fetching the dataconext, we will switch IsBusy accordingly
            using (var token = BusyStack.GetToken())
            {
                var currentContext = Content.DataContext as ObservableObject;
                var newContext     = GetDataContext.Invoke();

                if (currentContext == null && newContext == null)
                {
                    return;
                }

                if (EqualityComparer <ObservableObject> .Default.Equals(currentContext, newContext))
                {
                    return;
                }

                Content.DataContext = newContext;
            }
        }
Example #3
0
 public Scene()
 {
     BusyStack           = new BusyStack();
     BusyStack.OnChanged = (hasItems) =>
     {
         IsBusy = hasItems;
     };
 }
        public void RemoveRange(IList items)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            using (BusyStack.GetToken())
                Items.RemoveRange(items);
        }
        public void AddRange(IEnumerable <T> items)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            using (BusyStack.GetToken())
                Items.AddRange(items);
        }
        public void Add(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            using (BusyStack.GetToken())
                Items.Add(item);
        }
        private void InitializeProperties()
        {
            _itemsLock = new object();

            Items = new RangeObservableCollection <T>();
            Items.CollectionChanged += ItemsCollectionChanged;

            BusyStack           = new BusyStack();
            BusyStack.OnChanged = (hasItems) => IsBusy = hasItems;

            View = CollectionViewSource.GetDefaultView(Items);

            // initial Notification, so that UI recognizes the value
            OnPropertyChanged(nameof(Count));
        }
        private async void MagickImageControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (IsBusy)
            {
                return;
            }

            using (BusyStack.GetToken())
            {
                try
                {
                    Image = await AnalyzeContext(e);
                }
                catch (UnauthorizedAccessException)
                {
                    Image = default(BitmapSource);

                    // this exception should be logged, instead of being ignored
                }
            }
        }
Example #9
0
 public BusyToken(BusyStack stack) : base(stack)
 {
     stack.Push(this);
 }
 public void Clear()
 {
     using (BusyStack.GetToken())
         Items.Clear();
 }
 public void Remove(T item)
 {
     using (BusyStack.GetToken())
         Items.Remove(item);
 }