Пример #1
0
        private async Task AsyncOnViewModelChatWindowsListChanged(AsyncListChangedEventHandler <ChatWindowViewModel> ea)
        {
            await Task.Run(() =>
            {
                try
                {
                    switch (ea.ChangedEventArgs.ListChangedType)
                    {
                    case ListChangedType.ItemAdded:
                        {
                            UiWindow.Window.UIThread(() =>
                            {
                                ChatWindowViewModel newElem = ea.ChangedElemnt;

                                _ChatWindows.Add(new ChatWindow(this, newElem, _MainWindow));
                                _ChatWindows[_ChatWindows.Count - 1].Show();
                            });
                        }
                        break;

                    case ListChangedType.ItemDeleted:
                        {
                        }
                        break;
                    }
                }
                catch (Exception e)
                {
                    Logger.WriteLog(e);
                }
            });
        }
        protected override void OnListChanged(ListChangedEventArgs e)
        {
            switch (e.ListChangedType)
            {
            case ListChangedType.ItemChanged:
            {
                T   item = this.Items[e.NewIndex];
                var ea   = new AsyncListChangedEventHandler <T>(this, item, e);
                //Task.Run(async () =>
                //{
                _AsyncListChanged.InvokeAsync(ea);
                //});
            }
            break;

            case ListChangedType.ItemAdded:
            {
                T   item = this.Items[e.NewIndex];
                var ea   = new AsyncListChangedEventHandler <T>(this, item, e);
                //Task.Run(async () =>
                //{
                _AsyncListChanged.InvokeAsync(ea);
                //});
            }
            break;
            }

            base.OnListChanged(e);
        }
        protected override void RemoveItem(int index)
        {
            T itemToDelete = this.Items[index];

            var tmp = new ListChangedEventArgs(ListChangedType.ItemDeleted, index);

            var ea = new AsyncListChangedEventHandler <T>(this, itemToDelete, new ListChangedEventArgs(ListChangedType.ItemDeleted, index));

            //Task.Run(async () =>
            //{
            _AsyncListChanged.InvokeAsync(ea);
            //});

            base.RemoveItem(index);
        }
Пример #4
0
        private async Task OnChatWindowsChangeAsync(AsyncListChangedEventHandler <ChatWindowViewModelSettings> e)
        {
            NotifyPropertyChanged("ChatWindows." + e.ChangedEventArgs.ToString());

            await _ChatWindowsListChangedAsync.InvokeAsync(e);
        }
 private async Task OnChatWindowsListChangeAsync(AsyncListChangedEventHandler <ChatWindowViewModel> e)
 {
     await _ChatWindowsListChangedAsync.InvokeAsync(e);
 }
Пример #6
0
        private async Task AsyncOnViewModelWindowsListChanged(AsyncListChangedEventHandler <ChatWindowViewModel> ea)
        {
            switch (ea.ChangedEventArgs.ListChangedType)
            {
            case ListChangedType.ItemAdded:
            {
                await UiWindow.Window.UIThreadAsync(() =>
                    {
                        ChatWindowViewModel newElem = ea.ChangedElemnt;

                        var reslut = _TataruUIModel.ChatWindows.FirstOrDefault(x => x.WinId == newElem.WinId);
                        if (reslut == null)
                        {
                            var sett = newElem.GetSettings();
                            _TataruUIModel.ChatWindows.Add(sett);

                            var binder = new PropertyBinder(_TataruUIModel.ChatWindows[_TataruUIModel.ChatWindows.Count - 1], newElem);
                            CreateBinderCouples(binder);
                            _PropertyBinders.Add(binder);
                        }
                    });
            }
            break;

            case ListChangedType.ItemDeleted:
            {
                await Task.Run(() =>
                    {
                        SpinWait.SpinUntil(() => !deletingObject);
                        lock (lockObj)
                        {
                            deletingObject = true;
                        }
                    });

                await UiWindow.Window.UIThreadAsync(() =>
                    {
                        try
                        {
                            ChatWindowViewModel deletedElem = ea.ChangedElemnt;

                            ChatWindowViewModelSettings reslut = _TataruUIModel.ChatWindows.FirstOrDefault(x => x.WinId == deletedElem.WinId);

                            if (reslut != null)
                            {
                                _TataruUIModel.ChatWindows.Remove(reslut);

                                RemoveChatWindow(_ChatWindows, reslut.WinId);

                                try
                                {
                                    PropertyBinder binder = _PropertyBinders.FirstOrDefault(x => x.Object1 == reslut && x.Object2 == deletedElem);

                                    if (binder == null)
                                    {
                                        binder = _PropertyBinders.FirstOrDefault(x => x.Object2 == reslut && x.Object1 == deletedElem);
                                    }

                                    if (binder != null)
                                    {
                                        binder.Stop();
                                        _PropertyBinders.Remove(binder);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Logger.WriteLog(e);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.WriteLog(e);
                        }
                    });

                deletingObject = false;
            }

            break;
            }
        }
Пример #7
0
        private async Task AsyncOnSettingsWindowsListChanged(AsyncListChangedEventHandler <ChatWindowViewModelSettings> ea)
        {
            switch (ea.ChangedEventArgs.ListChangedType)
            {
            case ListChangedType.ItemAdded:
            {
                await UiWindow.Window.UIThreadAsync(() =>
                    {
                        ChatWindowViewModelSettings newElem = ea.ChangedElemnt;

                        ChatWindowViewModel reslut = null;

                        reslut = _TataruViewModel.ChatWindows.FirstOrDefault(x => x.WinId == newElem.WinId);


                        if (reslut == null)
                        {
                            try
                            {
                                TataruViewModel.AddNewChatWindow(newElem);
                            }
                            catch (Exception e)
                            {
                                Logger.WriteLog(e);
                            }

                            var binder = new PropertyBinder(newElem, _TataruViewModel.ChatWindows[_TataruViewModel.ChatWindows.Count - 1]);
                            CreateBinderCouples(binder);
                            _PropertyBinders.Add(binder);
                        }
                    });
            }
            break;

            case ListChangedType.ItemDeleted:
            {
                await Task.Run(() =>
                    {
                        SpinWait.SpinUntil(() => !deletingObject);
                        lock (lockObj)
                        {
                            deletingObject = true;
                        }
                    });

                await UiWindow.Window.UIThreadAsync(() =>
                    {
                        try
                        {
                            ChatWindowViewModelSettings deletedElem = ea.ChangedElemnt;

                            var elementToDelete = _TataruViewModel.ChatWindows.FirstOrDefault(x => x.WinId == deletedElem.WinId);

                            if (elementToDelete != null)
                            {
                                _TataruViewModel.DeleteChatWindow(_TataruViewModel.ChatWindows.IndexOf(elementToDelete));

                                RemoveChatWindow(_ChatWindows, elementToDelete.WinId);

                                var binder = _PropertyBinders.FirstOrDefault(x => x.Object1 == elementToDelete && x.Object2 == deletedElem);
                                if (binder == null)
                                {
                                    binder = _PropertyBinders.FirstOrDefault(x => x.Object2 == elementToDelete && x.Object1 == deletedElem);
                                }

                                if (binder != null)
                                {
                                    binder.Stop();

                                    _PropertyBinders.Remove(binder);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.WriteLog(e);
                        }
                    });

                deletingObject = false;
            }
            break;
            }
        }