public MainWindow() { InitializeComponent(); var button = new Button { Content = "This is a button" }; var textBlock = new TextBlock { Text = "Test" }; button.SetValue(Grid.ColumnProperty, 0); button.SetValue(Grid.RowProperty, 0); textBlock.SetValue(Grid.ColumnProperty, 1); textBlock.SetValue(Grid.RowProperty, 0); TheGrid.Children.Add(button); TheGrid.Children.Add(textBlock); //TheOrderedStackPanel.Order(); }
private async Task DisplayAllFiles() { Debug.WriteLine("-- GETTING FILES"); StorageFolder appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; StorageFolder dataFolder = await appInstalledFolder.GetFolderAsync(GlobalData.dataFolder); IReadOnlyList <StorageFile> fileList = await dataFolder.GetFilesAsync(); this.ImageHolder.Opacity = 0; this.ImageHolder.Width = 1500; this.ImageHolder.Height = 1500; this.ImageHolder.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); this.ImageHolder.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength() }); this.ImageHolder.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength() }); this.ImageHolder.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength() }); this.ImageHolder.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength() }); this.ImageHolder.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength() }); this.ImageHolder.RowDefinitions.Add(new RowDefinition() { Height = new GridLength() }); Button button = new Button(); button.Name = "IDC_Classify"; button.Content = "Classify All Images"; button.Click += IDC_Classify_Click; button.Width = 250; button.Height = 75; button.Foreground = new SolidColorBrush(Windows.UI.Colors.White); button.SetValue(Grid.ColumnProperty, 6); button.SetValue(Grid.RowProperty, 0); this.ImageHolder.Children.Add(button); this.ImageHolder.RowDefinitions.Add(new RowDefinition() { Height = new GridLength() }); var result = new ObservableCollection <BitmapImage>(); var i = 0; var row = 1; var column = 0; foreach (StorageFile file in fileList) { Debug.WriteLine(file.Name); using (var stream = await file.OpenAsync(FileAccessMode.Read)) { var bitmapDecoder = await BitmapDecoder.CreateAsync(stream); var pixelProvider = await bitmapDecoder.GetPixelDataAsync(); var bits = pixelProvider.DetachPixelData(); var softwareBitmap = new SoftwareBitmap( BitmapPixelFormat.Bgra8, (int)bitmapDecoder.PixelWidth, (int)bitmapDecoder.PixelHeight, BitmapAlphaMode.Premultiplied); softwareBitmap.CopyFromBuffer(bits.AsBuffer()); var softwareBitmapSource = new SoftwareBitmapSource(); await softwareBitmapSource.SetBitmapAsync(softwareBitmap); var source = new SoftwareBitmapSource(); await source.SetBitmapAsync(softwareBitmap); if (i != 0 && i % 6 == 0) { Debug.WriteLine("-- New Image Row " + row); this.ImageHolder.RowDefinitions.Add( new RowDefinition() { Height = GridLength.Auto }); column = 0; row++; } Image image = new Image(); image.Source = softwareBitmapSource; image.Name = file.Name; image.Width = 250; image.Height = 250; image.SetValue(Grid.ColumnProperty, column); image.SetValue(Grid.RowProperty, row); this.ImageHolder.Children.Add(image); column++; i++; } } this.ImageHolder.Opacity = 1; }