Beispiel #1
0
        private void PopulateGrid()
        {
            mainGrid.ColumnDefinitions.Clear();
            mainGrid.RowDefinitions.Clear();
            mainGrid.Children.Clear();
            TileViewProperties tileCollection = new TileViewProperties();
            int imageWidth  = 302;
            int imageHeight = 180;

            Random random = new Random();

            int columnCount = Convert.ToInt32((rootGrid.ActualWidth - 50) / (imageWidth + 20));
            int rowCount    = Convert.ToInt32((rootGrid.ActualHeight - 120) / (imageHeight + 20));

            for (int i = 0; i < rowCount; i++)
            {
                mainGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(imageHeight + 10)
                });
            }

            for (int i = 0; i < columnCount; i++)
            {
                mainGrid.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(imageWidth + 10)
                });
            }

            int index = 0;

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    ContactView contactView = new ContactView();
                    contactView.Margin      = new Thickness(10);
                    contactView.DataContext = tileCollection.Images[index];
                    Grid.SetRow(contactView, i);
                    Grid.SetColumn(contactView, j);
                    mainGrid.Children.Add(contactView);
                    index++;
                    if (index == 9)
                    {
                        index = 0;
                    }
                }
            }
        }
        private void PopulateGrid()
        {
            mainGrid.ColumnDefinitions.Clear();
            mainGrid.RowDefinitions.Clear();
            mainGrid.Children.Clear();
            TileViewProperties tileCollection = new TileViewProperties();
            int imageWidth  = 130;
            int imageHeight = 130;

            Random random = new Random();

            int columnCount = Convert.ToInt32((rootGrid.ActualWidth - 20) / (imageWidth + 20));
            int rowCount    = Convert.ToInt32((rootGrid.ActualHeight - 110) / (imageHeight + 20));

            for (int i = 0; i < rowCount; i++)
            {
                mainGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(imageHeight + 10)
                });
            }

            for (int i = 0; i < columnCount; i++)
            {
                mainGrid.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(imageWidth + 10)
                });
            }

            int index = 0;

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    if (index == 8)
                    {
                        index = 0;
                    }
                    PhotosView photosview = new PhotosView();
                    photosview.DataContext = tileCollection.Images[index];
                    Grid.SetRow(photosview, i);
                    Grid.SetColumn(photosview, j);
                    mainGrid.Children.Add(photosview);
                    index++;
                }
            }
        }