Exemple #1
0
        public void CollectionViewSortTest()
        {
            ObservableCollection <int> collection     = new ObservableCollection <int>(new[] { 0, 1, 9, 8, 2, 3, 7, 6, 4, 5 });
            CollectionView             collectionView = new CollectionView(collection);

            NotifyCollectionChangedEventArgs lastChangeArgs = null;
            int currentChangedCount = 0;

            collectionView.CollectionChanged += (sender, e) => lastChangeArgs = e;
            collectionView.CurrentChanged    += (sender, e) => currentChangedCount++;

            collectionView.CurrentItem = 3;
            Assert.AreEqual(3, collectionView.CurrentItem);
            Assert.AreEqual(5, collectionView.CurrentItemIndex);
            Assert.AreEqual(1, currentChangedCount);

            collectionView.SortKeySelector = item => item;
            Assert.AreEqual(3, collectionView.CurrentItem);
            Assert.AreEqual(3, collectionView.CurrentItemIndex);
            Assert.AreEqual(2, currentChangedCount);
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, lastChangeArgs.Action);
            CollectionAssert.AreEqual(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, collectionView.Cast <int>().ToArray());

            collectionView.SortDirection = ListSortDirection.Descending;
            Assert.AreEqual(3, collectionView.CurrentItem);
            Assert.AreEqual(6, collectionView.CurrentItemIndex);
            Assert.AreEqual(3, currentChangedCount);
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, lastChangeArgs.Action);
            CollectionAssert.AreEqual(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, collectionView.Cast <int>().ToArray());
        }
Exemple #2
0
 public ObservableViewModelCollection(CollectionView source, Func <TModel, TViewModel> viewModelFactory)
     : base(source.Cast <TModel>().Select(model => viewModelFactory(model)))
 {
     _source           = source;
     _viewModelFactory = viewModelFactory;
     _listener         = new CollectionChangedEventListener(_source, OnSourceCollectionChanged);
 }
Exemple #3
0
        public AddInViewModel()
        {
            _items =
                (CollectionView)
                CollectionViewSource.GetDefaultView(
                    ReviveThisApplication.Default.AddIns.Items
                    .Select(s => new AddInInformation(s))
                    .OrderBy(ob => ob.FileName));

            if (_items == null)
            {
                return;
            }

            Items = _items;

            var groupDescription = new PropertyGroupDescription("FileName");

            if (_items.GroupDescriptions != null)
            {
                _items.GroupDescriptions.Add(groupDescription);
            }

            var first = _items.Cast <AddInInformation>().FirstOrDefault();

            if (first != null)
            {
                SelectedItem = first;
            }
        }
Exemple #4
0
        public MainPage()
        {
            InitializeComponent();

            dragHelper = new DragDropHelper();

            State = Persistence.GlobalState.Load();

            State.Translations.ChangeLocale(Options.Locale);
            DataContext = State;

            SetWindowTitle();

            // TODO: move this block to XAML, see http://www.galasoft.ch/mydotnet/articles/article-2007081301.aspx
            itemCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(LiftItems);
            itemCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
            itemCollectionView.SortDescriptions.Add(new SortDescription("Category", ListSortDirection.Descending));
            itemCollectionView.SortDescriptions.Add(new SortDescription("Title", ListSortDirection.Ascending));

            LiftItems.CollectionChanged += (sender, e) =>
            {
                Console.WriteLine(DateTime.Now + " LiftItems.CollectionChanged/2 triggered");
                //UpdateLiftItems();
            };
            lbLiftItems.SelectedIndex = 0;
            lbLiftItems.Focus();

            // set jumplist items in case they were changed outside of the program
            Helpers.JumpListHelper.Update(itemCollectionView.Cast <Data.LiftItem>());
            //lbLiftItems.DragEnter += new DragEventHandler(lbLiftItems_DragEnter);
            //lbLiftItems.DragOver += new DragEventHandler(lbLiftItems_DragOver);
        }
Exemple #5
0
        private void UpdateLiftItems(bool refresh = true)
        {
            if (refresh)
            {
                itemCollectionView.Refresh();
            }
            Persistence.LiftItemsStore.Save(LiftItems);

            Helpers.JumpListHelper.Update(itemCollectionView.Cast <Data.LiftItem>());
            //Helpers.JumpListHelper.Update(LiftItems);
        }
Exemple #6
0
        /// <summary>
        /// Constructs pie pieces and adds them to the visual tree for this control's canvas
        /// </summary>
        private void ConstructPiePieces()
        {
            CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(this.DataContext);

            if (myCollectionView == null)
            {
                return;
            }

            double halfWidth = ((this.ActualHeight < this.ActualWidth ? this.ActualHeight : this.ActualWidth)
                                - this.Margin.Top - this.Margin.Bottom) / 2;
            double innerRadius = halfWidth * HoleSize;

            // compute the total for the property which is being plotted
            double total = myCollectionView.Cast <object>().Sum(item => GetPlottedPropertyValue(item));

            CleanupPie();

            // add the pie pieces
            double accumulativeAngle = 0;

            foreach (Object item in myCollectionView)
            {
                bool selectedItem = item == myCollectionView.CurrentItem;

                double wedgeAngle = GetPlottedPropertyValue(item) * 360 / total;

                PiePiece piece = new PiePiece()
                {
                    Radius                                     = halfWidth,
                    InnerRadius                                = innerRadius,
                    CenterX                                    = halfWidth,
                    CenterY                                    = halfWidth,
                    PushOut                                    = (selectedItem ? 10.0 : 0),
                    WedgeAngle                                 = wedgeAngle,
                    PieceValue                                 = GetPlottedPropertyValue(item),
                    RotationAngle                              = accumulativeAngle,
                    Fill                                       = ColorSelector != null?ColorSelector.SelectBrush(item, myCollectionView.IndexOf(item)) : Brushes.Black,
                                                  PieceCaption = GetPlottedCaptionPropertyValue(item),
                                                  // record the index of the item which this pie slice represents
                                                  Tag     = myCollectionView.IndexOf(item),
                                                  ToolTip = new ToolTip()
                };

                piece.ToolTipOpening += PiePieceToolTipOpening;
                piece.MouseUp        += PiePieceMouseUp;

                piePieces.Add(piece);
                canvas.Children.Insert(0, piece);

                accumulativeAngle += wedgeAngle;
            }
        }
Exemple #7
0
        public async Task GetMessageTypesList()
        {
            List <MessageType> messageTypes = _mappers.GetMessageTypeDTOToMessageTypeMapper().Map <IEnumerable <MessageTypeDTO>, List <MessageType> >(await _mailService.GetMessageTypesAsync());

            messageTypes.FirstOrDefault(m => m.ID == (int)Enums.MessageTypes.Inbox).Text = "Все входящие";
            MessageTypes = new CollectionView(messageTypes);

            ICollectionView filterView = CollectionViewSource.GetDefaultView(MessageTypes.SourceCollection.Cast <MessageType>());

            filterView.Filter = item => { return((item as MessageType) != null && (item as MessageType).ID > (int)Enums.MessageTypes.None && (item as MessageType).ID != (int)Enums.MessageTypes.InboxNone); };
            MessageTypes      = filterView;

            // Bug: При обновлении переключается на самый первый пункт, хотя в выбранном нужный
            SelectedLeftMenuItem = MessageTypes.Cast <MessageType>().ToList().FirstOrDefault(m => m.ID == (int)Enums.MessageTypes.InboxParticipant); // TODO: Get from AppSettings in DB
        }
Exemple #8
0
        public void CollectionViewFilterTest()
        {
            ObservableCollection <int> collection     = new ObservableCollection <int>(new[] { 0, 1, 9, 8, 2, 3, 7, 6, 4, 5 });
            CollectionView             collectionView = new CollectionView(collection);

            NotifyCollectionChangedEventArgs lastChangeArgs = null;
            int currentChangedCount = 0;

            collectionView.CollectionChanged += (sender, e) => lastChangeArgs = e;
            collectionView.CurrentChanged    += (sender, e) => currentChangedCount++;

            collectionView.CurrentItem = 2;
            Assert.AreEqual(2, collectionView.CurrentItem);
            Assert.AreEqual(4, collectionView.CurrentItemIndex);
            Assert.AreEqual(1, currentChangedCount);

            collectionView.FilterPredicate = item => (int)item % 2 == 0;
            Assert.AreEqual(2, collectionView.CurrentItem);
            Assert.AreEqual(2, collectionView.CurrentItemIndex);
            Assert.AreEqual(2, currentChangedCount);
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, lastChangeArgs.Action);
            CollectionAssert.AreEqual(new[] { 0, 8, 2, 6, 4 }, collectionView.Cast <int>().ToArray());
        }
Exemple #9
0
        private void ExportCSV()
        {
            String text = "";

            text = "\"Skåp\",\"Nycklar\",\"Status\",\"Förnamn\",\"Efternamn\",\"Åk\",\"Klass\",\"År\",\"Commentar\"\n";


            List <MyItem>  list = sql.getAllLockers("", "", "", "", "");
            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(list);

            view.Culture = new CultureInfo("sv-SE");

            view.SortDescriptions.Clear();

            view.SortDescriptions.Add(new SortDescription("P.Grade", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("P.Class", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("P.Lastname", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("P.Firstname", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("L.Status", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("L.Number", ListSortDirection.Ascending));
            list = view.Cast <MyItem>().ToList();
            for (int i = 0; i < list.Count; i++)
            {
                MyItem n = list[i];
                // Console.WriteLine("JJ" + m.L.Comment.Replace("\n", " ") + "JJ");
                string history = n.L.HistoryShort.Replace("\"", "'");
                text += "\"" + n.L.Number + "\",\"" + n.L.Keys + "\",\"" + n.L.StatusText + "\",\"" + n.P.Firstname + "\",\"" + n.P.Lastname + "\",\"" + n.P.Grade + "\",\"" + n.P.Class + "\",\"" + n.P.Year + "\",\"" + history + "\"\n";
            }
            try
            {
                File.WriteAllText(dir + "skåp.csv", text, Encoding.UTF8);
            }
            catch (Exception)
            {
            }
        }
 IEnumerator <T> IEnumerable <T> .GetEnumerator()
 {
     return(CollectionView.Cast <T>().GetEnumerator());
 }
Exemple #11
0
        public void CollectionViewChangeTest()
        {
            ObservableCollection <int> collection     = new ObservableCollection <int>(new[] { 0, 1, 9, 8, 2, 3, 7, 6, 4, 5 });
            CollectionView             collectionView = new CollectionView(collection);

            NotifyCollectionChangedEventArgs lastChangeArgs = null;
            int currentChangedCount = 0;

            collectionView.CollectionChanged += (sender, e) => lastChangeArgs = e;
            collectionView.CurrentChanged    += (sender, e) => currentChangedCount++;

            collectionView.CurrentItem = 3;
            Assert.AreEqual(3, collectionView.CurrentItem);
            Assert.AreEqual(5, collectionView.CurrentItemIndex);
            Assert.AreEqual(1, currentChangedCount);

            collectionView.CurrentItemIndex = 3;
            Assert.AreEqual(8, collectionView.CurrentItem);
            Assert.AreEqual(3, collectionView.CurrentItemIndex);
            Assert.AreEqual(2, currentChangedCount);

            collection.Add(10);
            Assert.AreEqual(8, collectionView.CurrentItem);
            Assert.AreEqual(3, collectionView.CurrentItemIndex);
            Assert.AreEqual(2, currentChangedCount);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, lastChangeArgs.Action);
            Assert.AreEqual(10, lastChangeArgs.NewStartingIndex);
            CollectionAssert.AreEqual(new [] { 10 }, lastChangeArgs.NewItems.Cast <int>().ToArray());
            CollectionAssert.AreEqual(new [] { 0, 1, 9, 8, 2, 3, 7, 6, 4, 5, 10 }, collectionView.Cast <int>().ToArray());

            collection.Insert(0, 11);
            Assert.AreEqual(8, collectionView.CurrentItem);
            Assert.AreEqual(4, collectionView.CurrentItemIndex);
            Assert.AreEqual(3, currentChangedCount);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, lastChangeArgs.Action);
            Assert.AreEqual(0, lastChangeArgs.NewStartingIndex);
            CollectionAssert.AreEqual(new[] { 11 }, lastChangeArgs.NewItems.Cast <int>().ToArray());
            CollectionAssert.AreEqual(new[] { 11, 0, 1, 9, 8, 2, 3, 7, 6, 4, 5, 10 }, collectionView.Cast <int>().ToArray());

            collection.RemoveAt(4);
            Assert.AreEqual(2, collectionView.CurrentItem);
            Assert.AreEqual(4, collectionView.CurrentItemIndex);
            Assert.AreEqual(4, currentChangedCount);
            Assert.AreEqual(NotifyCollectionChangedAction.Remove, lastChangeArgs.Action);
            Assert.AreEqual(4, lastChangeArgs.OldStartingIndex);
            CollectionAssert.AreEqual(new[] { 8 }, lastChangeArgs.OldItems.Cast <int>().ToArray());
            CollectionAssert.AreEqual(new[] { 11, 0, 1, 9, 2, 3, 7, 6, 4, 5, 10 }, collectionView.Cast <int>().ToArray());

            collection[4] = 12;
            Assert.AreEqual(12, collectionView.CurrentItem);
            Assert.AreEqual(4, collectionView.CurrentItemIndex);
            Assert.AreEqual(5, currentChangedCount);
            Assert.AreEqual(NotifyCollectionChangedAction.Replace, lastChangeArgs.Action);
            Assert.AreEqual(4, lastChangeArgs.NewStartingIndex);
            CollectionAssert.AreEqual(new[] { 12 }, lastChangeArgs.NewItems.Cast <int>().ToArray());
            CollectionAssert.AreEqual(new[] { 2 }, lastChangeArgs.OldItems.Cast <int>().ToArray());
            CollectionAssert.AreEqual(new[] { 11, 0, 1, 9, 12, 3, 7, 6, 4, 5, 10 }, collectionView.Cast <int>().ToArray());

            collectionView.CurrentItemIndex = 20;
            Assert.IsNull(collectionView.CurrentItem);
            Assert.AreEqual(11, collectionView.CurrentItemIndex);
            Assert.AreEqual(6, currentChangedCount);

            collection.Add(13);
            Assert.IsNull(collectionView.CurrentItem);
            Assert.AreEqual(12, collectionView.CurrentItemIndex);
            Assert.AreEqual(7, currentChangedCount);
            CollectionAssert.AreEqual(new[] { 11, 0, 1, 9, 12, 3, 7, 6, 4, 5, 10, 13 }, collectionView.Cast <int>().ToArray());

            collection.RemoveAt(0);
            Assert.IsNull(collectionView.CurrentItem);
            Assert.AreEqual(11, collectionView.CurrentItemIndex);
            Assert.AreEqual(8, currentChangedCount);
            CollectionAssert.AreEqual(new[] { 0, 1, 9, 12, 3, 7, 6, 4, 5, 10, 13 }, collectionView.Cast <int>().ToArray());
        }