Example #1
0
        void OnTabsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (TabViewModel tab in e.NewItems)
                {
                    Messenger.Default.Send <DatabaseMessage>(DatabaseMessage.Add(tab.Model));
                    Configuration.AvailableTabs.Add(tab.Title);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (TabViewModel tab in e.OldItems)
                {
                    Messenger.Default.Send <DatabaseMessage>(DatabaseMessage.Remove(tab.Model));
                    Configuration.AvailableTabs.Remove(tab.Title);
                    Messenger.Default.Unregister(tab);

                    // Removing items one-by-one so that the NotifyCollectionChangedAction.Remove
                    // event is fired for each of them in the Applications collection.
                    foreach (var application in tab.Applications.ToList())
                    {
                        tab.Applications.Remove(application);
                    }
                }
                break;

            case NotifyCollectionChangedAction.Move:
                // TODO:
                break;
            }
        }
        void OnApplicationsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (ApplicationViewModel application in e.NewItems)
                {
                    Log.DebugFormat("Adding {0}", application.Title);
                    //IsExpanded = true;
                    application.Tab = Title;

                    Messenger.Default.Send <DatabaseMessage>(DatabaseMessage.Add(application.Model));
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (ApplicationViewModel application in e.OldItems)
                {
                    Log.DebugFormat("Removing {0}", application.Title);
                    Messenger.Default.Send <DatabaseMessage>(DatabaseMessage.Remove(application.Model));
                }
                break;

            case NotifyCollectionChangedAction.Move:
                // TODO: Probably should save application positions?
                break;
            }
        }