Exemple #1
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            Monik?.ApplicationVerbose("Matrix.Drop");

            var card       = dropInfo.Data as CardViewModel;
            var targetCard = dropInfo.TargetItem as CardViewModel;

            // dirty fingers
            var targetIntersec = ((dropInfo.VisualTarget as ListView)
                                  .Parent as Grid)
                                 .Parent as Intersection;

            if (card.ColumnDeterminant != targetIntersec.ColumnDeterminant ||
                card.RowDeterminant != targetIntersec.RowDeterminant)
            {
                Monik?.ApplicationVerbose("Matrix.Drop move to other intersection");
                card.ColumnDeterminant = targetIntersec.ColumnDeterminant;
                card.RowDeterminant    = targetIntersec.RowDeterminant;
            }

            // Reorder
            card.Order = targetCard != null ? targetCard.Order - 1 : int.MaxValue;

            using (CardsObservable.Bind(out ReadOnlyObservableCollection <ICard> temp).Subscribe())
            {
                var targetCards = temp
                                  .Where(x => x.ColumnDeterminant == card.ColumnDeterminant &&
                                         x.RowDeterminant == card.RowDeterminant)
                                  .OrderBy(x => x.Order);

                int i = 0;
                foreach (var it in targetCards)
                {
                    it.Order = i;
                    i       += 10;
                }
            } //using
        }
Exemple #2
0
        public void RebuildGrid()
        {
            Monik?.ApplicationVerbose("Matrix.RebuildGrid started");

            MainGrid.Children.Clear();

            if (Rows == null || Columns == null ||
                Rows.Count == 0 || Columns.Count == 0)
            {
                Monik?.ApplicationVerbose("Matrix.RebuildGrid skip func");
                return;
            }

            var columns     = Columns.ToList();
            int columnCount = Columns.Count;
            var rows        = Rows.ToList();
            int rowCount    = Rows.Count;

            //////////////////
            // 1. Fill columns
            //////////////////
            MainGrid.ColumnDefinitions.Clear();
            // rows header
            MainGrid.ColumnDefinitions.Add(
                new ColumnDefinition {
                Width = new GridLength(30, GridUnitType.Pixel)
            });

            // columns
            for (int i = 0; i < columnCount; i++)
            {
                var it = columns[i];
                Monik?.ApplicationVerbose($"Matrix.RebuildGrid add column {it.Id}::{it.Name}::{it.Order}");

                var cd = new ColumnDefinition();
                cd.DataContext = it;
                cd.Width       = new GridLength(it.Size / 10.0, GridUnitType.Star);
                MainGrid.ColumnDefinitions.Add(cd);

                PropertyDescriptor pd = DependencyPropertyDescriptor.FromProperty(ColumnDefinition.WidthProperty, typeof(ColumnDefinition));
                pd.AddValueChanged(cd, new EventHandler(ColumnWidthPropertyChanged));

                ContentControl cc = new ContentControl();
                cc.Content         = it;
                cc.MouseMove      += Head_MouseMove;
                cc.ContextMenu     = HeadContextMenu;
                cc.ContentTemplate = (DataTemplate)this.Resources["DefaultHorizontalHeaderTemplate"];
                MainGrid.Children.Add(cc);

                // Update number of Cards in Column
                CardsObservable
                .Filter(x => x.ColumnDeterminant == it.Id)
                .ToCollection()
                .Subscribe(x => it.CurNumberOfCards = x.Count());

                // dont draw excess splitter
                if (i < columnCount - 1)
                {
                    MainGrid.Children.Add(BuildVerticalSpliter(i, rowCount));
                }

                Grid.SetColumn(cc, i + 1);
                Grid.SetRow(cc, 0);
            }

            ///////////////
            // 2. Fill rows
            ///////////////
            MainGrid.RowDefinitions.Clear();
            // columns header
            MainGrid.RowDefinitions.Add(
                new RowDefinition {
                Height = new GridLength(30, GridUnitType.Pixel)
            });

            // rows
            VerticalHeaders.Clear();
            for (int i = 0; i < rowCount; i++)
            {
                var it = rows[i];
                Monik?.ApplicationVerbose($"Matrix.RebuildGrid add row {it.Id}::{it.Name}::{it.Order}");

                var rd = new RowDefinition();
                rd.DataContext = it;
                rd.Height      = new GridLength(it.Size / 10.0, GridUnitType.Star);
                MainGrid.RowDefinitions.Add(rd);

                PropertyDescriptor pd = DependencyPropertyDescriptor.FromProperty(RowDefinition.HeightProperty, typeof(RowDefinition));
                pd.AddValueChanged(rd, new EventHandler(RowWidthPropertyChanged));

                ContentControl cc = new ContentControl();
                VerticalHeaders.Add(cc);
                cc.Content         = it;
                cc.MouseMove      += Head_MouseMove;
                cc.ContextMenu     = HeadContextMenu;
                cc.ContentTemplate = (DataTemplate)this.Resources["DefaulVerticalHeaderTemplate"];
                MainGrid.Children.Add(cc);

                // Update number of Cards in Row
                CardsObservable
                .Filter(x => x.RowDeterminant == it.Id)
                .ToCollection()
                .Subscribe(x => it.CurNumberOfCards = x.Count());

                // dont draw excess splitter
                if (i < rowCount - 1)
                {
                    MainGrid.Children.Add(BuildHorizontalSpliter(i, columnCount));
                }
                Grid.SetColumn(cc, 0);
                Grid.SetRow(cc, i + 1);
                Canvas.SetZIndex(cc, System.Int32.MaxValue);
            }

            ////////////////////////
            // 3. Fill Intersections
            ////////////////////////
            for (int i = 0; i < Columns.Count; i++)
            {
                for (int j = 0; j < Rows.Count; j++)
                {
                    int colDet = columns[i].Id;
                    int rowDet = rows[j].Id;

                    CardsObservable
                    .Filter(x => x.ColumnDeterminant == colDet && x.RowDeterminant == rowDet)
                    .Sort(SortExpressionComparer <ICard> .Ascending(c => c.Order))
                    .ObserveOnDispatcher()
                    .Bind(out ReadOnlyObservableCollection <ICard> intersectionCards)
                    .Subscribe();

                    Intersection cell = new Intersection(this)
                    {
                        DataContext       = this,
                        ColumnDeterminant = colDet,
                        RowDeterminant    = rowDet,
                        SelfCards         = intersectionCards
                    };

                    MainGrid.Children.Add(cell);
                    Grid.SetColumn(cell, i + 1);
                    Grid.SetColumnSpan(cell, 1);
                    Grid.SetRow(cell, j + 1);
                    Grid.SetRowSpan(cell, 1);
                }
            }
            SwimLanePropertyChanged(this, null);
            Monik?.ApplicationVerbose("Matrix.RebuildGrid finished");
        }