0

First, let me state my intentions. This is the final result I am looking for.

Mockup Of Intent http://s18.postimg.org/x818zbfbb/image.png

The output of my code, however, fails to achieve this. Here's what I did. This is my MainWindow XAML.

<Window x:Class="App.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="" Height="200" Width="400" WindowStartupLocation="CenterScreen" Name="ViewData"> <Grid Name="splMain" Background="{StaticResource GreyGradient}"></Grid> </Window> 

And this is the C# code for the dynamic RowDefitions creation:

private void ViewImgData(SubPod subPod) { var wb = new WebBrowser(); wb.Navigate(subPod.Image.Src); var rowDefinition = new RowDefinition(); rowDefinition.Height = GridLength.Auto; splMain.RowDefinitions.Add(rowDefinition); Grid.SetRow(wb, 0); ((MainWindow)System.Windows.Application.Current.MainWindow).splMain.Children.Add(wb); } 

This I am calling from over here. It is guaranteed that this foreach loop would run more than once. However, my output window shows only 1 image instead of 2 or more, that too not taking up the whole space of the Window.

foreach (SubPod subPod in pod.SubPods) { Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(() => ViewImgData(subPod))); } 

Where have I mistaken? Thanks.

5
  • Looks like you create new RowDefinition each time but then you put each WebBrowser always in the 0 row Commented Apr 20, 2015 at 14:36
  • Really? Looks like you have a basic problem with your webbrowser based logic since you post a new question having the same problem, just with another container... Besides that, don´t put each element into the 0th row Commented Apr 20, 2015 at 14:36
  • @Ben Sorry, but I am kinda in a fix here. I am unable to get the containers to work and DockPanel is not an option according to my instructor. Commented Apr 20, 2015 at 14:40
  • If you really just want to show images, why not use the <Image> Control? Just curious. Commented Apr 20, 2015 at 14:42
  • @Ben Instructor guidelines. And I can't ask him what you just asked without risking my grades :'( Commented Apr 20, 2015 at 14:47

1 Answer 1

1

You add new rows, but place the new webbrowser component in the 0th row. Try

Grid.SetRow(wb, splMain.RowDefinitions.Count-1); 

instead, since you need to place new content in the new row.

EDIT: To fit the grid height and width try adding this to your splMain grid

Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType={x:Type Window}}" Height="{Binding ActualHeight,RelativeSource={RelativeSource AncestorType={x:Type Window}}" 

see also Stretch Grid to window size

Sign up to request clarification or add additional context in comments.

3 Comments

Works! But is there a way to fill the whole window? This seems to cover only the top half. I have set VerticalAlignment="Stretch" HorizontalAlignment="Stretch" but not working.
Does the grid fill the whole window? Maybe you generate to much rows with "empty" webbrowsers? How big are your webbrowsers? Maybe they just don´t fill the grid?
The grid fills just the top half. The webbrowsers should fill the grid and empty webbrowsers are not the culprit. any other suggestion?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.