Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FoxTube/FoxTube/VideoGrid.xaml.cs
T
2018-06-07 10:29:00 +03:00

86 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Diagnostics;
using System.Timers;
using Windows.UI.Core;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace FoxTube
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class VideoGrid : Page
{
int cols = 0;
List<VideoCard> cards = new List<VideoCard>();
public VideoGrid()
{
this.InitializeComponent();
}
public void AddCards(VideoCard vCard)
{
cards.Add(vCard);
}
void SetColumns(int num)
{
cols = num;
for (int k = 0; k < grid.ColumnDefinitions.Count; k++)
grid.ColumnDefinitions[k].Width = new GridLength(1, GridUnitType.Star);
for (int k = num; k < grid.ColumnDefinitions.Count; k++)
grid.ColumnDefinitions[k].Width = new GridLength(0);
col0.Children.Clear();
col1.Children.Clear();
col2.Children.Clear();
col3.Children.Clear();
for (int k = 0; k < cards.Count; k += num)
col0.Children.Add(cards[k]);
if(num > 1)
{
for (int k = 1; k < cards.Count; k += num)
col1.Children.Add(cards[k]);
if(num > 2)
{
for (int k = 2; k < cards.Count; k += num)
col2.Children.Add(cards[k]);
if(num > 3)
{
for (int k = 3; k < cards.Count; k += num)
col3.Children.Add(cards[k]);
}
}
}
}
private void grid_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (e.NewSize.Width >= 1000 && cols != 4)
SetColumns(4);
else if (e.NewSize.Width >= 800 && e.NewSize.Width < 1000 && cols != 3)
SetColumns(3);
else if (e.NewSize.Width >= 600 && e.NewSize.Width < 800 && cols != 2)
SetColumns(2);
else if (e.NewSize.Width < 600 && cols != 1)
SetColumns(1);
}
}
}