Beispiel #1
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.mainGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 2:
                this.flip_image = ((MemberSignInSystem.ModernUI.Content.FlipImage)(target));
                return;
            }
            this._contentLoaded = true;
        }
        private void UpdateImageGrid(Size newSize)
        {
            GridLength sideLength;
            int        numCols = 0, numRows = 0;

            if ((bool)OneImageBool)
            {
                sideLength = new GridLength(Math.Min(newSize.Width, newSize.Height));
                numCols    = 1;
                numRows    = 1;
            }
            else
            {
                double targetSideLength = 225;
                numCols = (int)(newSize.Width / targetSideLength);
                if (newSize.Width % targetSideLength > (targetSideLength / 2) || numCols == 0)
                {
                    numCols += 1;
                }
                numRows = (int)(newSize.Height / targetSideLength);
                if (newSize.Height % targetSideLength > (targetSideLength / 2) || numRows == 0)
                {
                    numRows += 1;
                }
                double sideLengthDouble = (double)Math.Min(newSize.Width / numCols, newSize.Height / numRows);
                sideLength = new GridLength(sideLengthDouble);
            }

            // Make sure ImageGrid has the right number of FlipImage children.
            if (numCols * numRows == ImageGrid.Children.Count)
            {
                // This will effect all row and column definitions in the grid.
                ImageGrid.RowDefinitions.FirstOrDefault().Height = sideLength;
                return;
            }
            if (numCols * numRows > ImageGrid.Children.Count)
            {
                while (numCols * numRows > ImageGrid.Children.Count)
                {
                    if (flipImageStorage.Count > 0)
                    {
                        FlipImage addMe = flipImageStorage.Pop();
                        addMe.StartTimer();
                        ImageGrid.Children.Add(addMe);
                        continue;
                    }

                    FlipImage flipImage = new FlipImage();

                    // Force the FlipImages to do initial flip if they're new
                    flipImage.ImageList = this.ImageList;

                    flipImage.SetResourceReference(FlipImage.TransitionTypeProperty, "TransitionType");

                    Binding binding = new Binding
                    {
                        Path           = new PropertyPath("ImageList"),
                        RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FlipImageGrid), 1)
                    };
                    flipImage.SetBinding(FlipImage.ImageListProperty, binding);

                    ImageGrid.Children.Add(flipImage);
                }
            }
            if (numCols * numRows < ImageGrid.Children.Count)
            {
                while (numCols * numRows < ImageGrid.Children.Count)
                {
                    FlipImage toStore = ImageGrid.Children[ImageGrid.Children.Count - 1] as FlipImage;
                    ImageGrid.Children.RemoveAt(ImageGrid.Children.Count - 1);
                    toStore.StopTimer();
                    flipImageStorage.Push(toStore);
                }
            }

            // Ensure proper number of ColumnDefinitions and RowDefinitions.
            ColumnDefinitionCollection colDefs = ImageGrid.ColumnDefinitions;
            RowDefinitionCollection    rowDefs = ImageGrid.RowDefinitions;

            colDefs.Clear(); rowDefs.Clear();
            for (int x = 0; x < numCols; x++)
            {
                for (int y = 0; y < numRows; y++)
                {
                    if (y == 0)
                    {
                        colDefs.Add(new ColumnDefinition()
                        {
                            Width = sideLength, SharedSizeGroup = "FlipImageSharedSizeGroup"
                        });
                    }
                    if (x == 0)
                    {
                        rowDefs.Add(new RowDefinition()
                        {
                            Height = sideLength, SharedSizeGroup = "FlipImageSharedSizeGroup"
                        });
                    }
                }
            }

            // Set grid coordinates of each child in ImageGrid
            int count = 0;

            foreach (FlipImage flipImage in ImageGrid.Children)
            {
                Grid.SetColumn(flipImage, count % numCols);
                Grid.SetRow(flipImage, count / numCols);
                count++;
            }
        }