Пример #1
0
        /// <summary>
        /// Event handler for watch items
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void WatchItemListChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            //Clear all watchfaces
            case NotifyCollectionChangedAction.Reset:

                WatchApps.Clear();
                AddSportApp();

                break;


            //Add viewmodel WatchFace
            case NotifyCollectionChangedAction.Add:

                foreach (IWatchItem item in e.NewItems)
                {
                    if (item.Type == WatchItemType.WatchApp)
                    {
                        if (item.ID == Guid.Parse(Constants.TennisAppGuid))
                        {
                            return;
                        }

                        try
                        {
                            var vmExistingWatchFace = WatchApps.Single(x => x.Model == item.ID);
                            WatchApps.Remove(vmExistingWatchFace);
                        }
                        catch (Exception) { };

                        vmWatchApp _newWatchApp = new vmWatchApp();
                        _newWatchApp.Name         = item.Name;
                        _newWatchApp.Model        = item.ID;
                        _newWatchApp.Developer    = item.Developer;
                        _newWatchApp.ImageFile    = item.File.Replace(".zip", ".gif");
                        _newWatchApp.Configurable = item.Configurable;
                        _newWatchApp.Item         = item;

                        WatchApps.Add(_newWatchApp);
                        LoadImage(_newWatchApp);

                        System.Diagnostics.Debug.WriteLine("vmWatchApps add item: " + item.Name);
                    }
                }

                //Sort
                var SortedApps = WatchApps.OrderBy(x => x.Name).ToList();
                WatchApps.Clear();

                foreach (var App in SortedApps)
                {
                    WatchApps.Add(App);
                }

                break;

            //Remove viewmodel WatchFace
            case NotifyCollectionChangedAction.Remove:

                foreach (IWatchItem item in e.OldItems)
                {
                    if (item.Type == WatchItemType.WatchApp)
                    {
                        vmWatchApp element = null;

                        foreach (var WatchApp in WatchApps)
                        {
                            if (WatchApp.Model == item.ID)
                            {
                                element = WatchApp;
                                break;
                            }
                        }

                        try
                        {
                            if (element != null)
                            {
                                WatchApps.Remove(element);
                            }
                        }
                        catch (Exception) { }

                        System.Diagnostics.Debug.WriteLine("vmWatchApps remove item: " + item.Name);
                    }
                }

                break;
            }
        }