Silverlight: How can I make this control take up all available space? - silverlight

I'm building an SL 4 app. The UI consists of three main parts: a top search bar, a bottom favorite bar, and the page content between the two. I would like the page content to take up all available space. Right now, it expands horizontally but not vertically. I'm not sure what I'm doing wrong. Here is the XAML:
<Grid x:Name="LayoutRoot" Background="BurlyWood">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<my:TopSearchBar x:Name="topSearchBar" Grid.Row="0" Navigator="{Binding ElementName=navigationFrame}" HorizontalAlignment="Stretch" VerticalAlignment="Top" />
<!-- I want this to take up all available space between the bottom and top elements -->
<navigation:Frame x:Name="navigationFrame" Source="/HomePage.xaml" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="BlueViolet" />
<my:BottomFavoritesBar x:Name="bottomFavoritesBar" Grid.Row="2" Navigator="{Binding ElementName=navigationFrame}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
</Grid>
What could I be doing wrong?

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

I can't reproduce your problem. For me, the grid does expand vertically to fill its space, and each of its child controls takes a third of the height.
Do you have this Grid inside something else, like a StackPanel, that would prevent it from filling all the vertical space?

Related

How do I make a WPF layout Grid fill all available vertical space?

I have a form with two Grid elements in a vertical StackPanel. I would have imagined the bottom Grid would automatically fill all available space, as I wish it to, but I have set heights on the Grid rows:
<RowDefinition Height="20" />
<RowDefinition Height="*" />
<RowDefinition Height="25" />
The short rows at the top and bottom are for labels and buttons, respectively. I have tried setting the grid's VerticallAllignment to Stretch, to no avail.
How do I anchor the bottom of the bottom grid to the bottom of the form, regardless of the form's height?
Essentially you can't use StackPanel to fill all available vertical space.
But you may use a DockPanel:
<DockPanel LastChildFill="True">
<Grid DockPanel.Dock="Top"/>
<Grid />
</DockPanel>
You may also use a Grid:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0"/>
<Grid Grid.Row="1"/>
</Grid>

Common ScrollViewer for multiple datagrid in a Screen

I have three user controls(all of them are dynamically created DataGrids) inside my main screen
i am trying to get a single scroll bar for all the three datagrids . the datagrids is created dynamically and it can be of different coloumns. So my requirement says that all datagrids should have same size. that means if datagrid2 is of bigger size, other two datagrids should grow to match with the datagrid2's size.
Here is how the basic xaml structure.
<ScrollViewer x:Name="ScrollViewer"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<Grid MinWidth="400">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<userControl1/>
<userControl2 Grid.Row="1"/>
<userControl3 Grid.Row="2"/>
</Grid>
</ScrollViewer
This is the type of thing where SharedSizeGroup comes to the rescue.
Try something like this;
<ScrollViewer>
<Grid MinWidth="400">
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="A"/>
<RowDefinition SharedSizeGroup="A"/>
<RowDefinition SharedSizeGroup="A"/>
</Grid.RowDefinitions>
<userControl1/>
<userControl2 Grid.Row="1"/>
<userControl3 Grid.Row="2"/>
</Grid>
</ScrollViewer>

How to style a page in XAML

I'm really new to XAML and Metro and my old HTML skills are not in my advance.
What i want to achive is to have 3 "rows", the top row as some kind of header, the last row as some kind of footer and then a scrollable content area in the middle.
How can I achive this in XAML for Metro?
I've tried the StackPanel but I can't get the middle one to stop expanding and putting my "footer" out or the screen.
read more about WPF Layouts,
Grid in WPF is similar to Table in HTML, you should do this if you want header and footer.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/> <!--Header-->
<RowDefinition/>
<RowDefinition Height="50"/> <!--Footer-->
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Header"></TextBlock>
<ScrollViewer Grid.Row="1">
<!--your Controls-->
</ScrollViewer>
<TextBlock Grid.Row="2" Text="Footer"></TextBlock>
</Grid>
Try this,
<Grid x:Name="GridName">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*" />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Header"/>
<StackPanel Orientation="Vertical" Grid.Row="1">
<!-- Other Controls -->
</StackPanel>
<TextBlock Grid.Row="2" Text="Footer" />
</Grid>

Force my grid to scale with 4:3 resolution

I designed my page to be 4:3 scalable and I'd like to have my grid to scale to 4:3 on any screen.
For example, on a 1900x1200, my grid will scale to 1600x1200 and we'll have 150px on each side of my grid. How can i manage to have this behavior ?
I've started with the following lines :
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1024*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="768*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1" Grid.Column="1" Name="my_grid" />
</Grid>
But I don't see how to manage the 4:3 thing. I'd like to force my grid to stretch until it has the highest 4:3 resolution possible and then let the free space on the sides.
Do you think I can manage to do this only in WPF ?
Thanks
You could use the ViewBox control. Design your XAML as you have done and place it inside it. The ViewBox will scale to fit the content to the available size. It will not resize the content so everything (ratios, width, etc.) will be left intact.
See http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox.aspx
Thanks to Sascha i did :
<Viewbox Name="grid_jeu" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" >
<MyControl Name="my_grid" />
</Viewbox>
My Control is designed this way :
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32" MaxHeight="32"/>
<RowDefinition Height="72" MaxHeight="72"/>
<RowDefinition Height="10" MaxHeight="10"/>
<RowDefinition Height="*"/>
<RowDefinition Height="20" MaxHeight="20"/>
<RowDefinition Height="90" MaxHeight="90"/>
<RowDefinition Height="32" MaxHeight="32"/>
</Grid.RowDefinitions>
</Grid>
I'd like to have only one row and one column which scale. As you can see I tried to put "MaxHeight" and "MaxWidth" to avoid my rows to scale but it doesn't work. When I launch my application I have my 309px column which scales to 420.

WPF Layout - Fill Height, Auto Scrollbar

The Grid at the bottom contains a ListBox. It stretches vertically, but the scrollbar does not appear when it reaches the bottom.
Layout --
<RibbonWindow ResizeMode="CanResize">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel>
<Ribbon ... />
<ListBox
VerticalAlignment="Stretch"
ScrollViewer.VerticalScrollBarVisibility="Auto"
/>
</StackPanel>
</Grid>
</RibbonWindow>
I have heard that StackPanels can cause this behavior, but replacing it with a Grid causes its own set of issues.
EDIT --
This Layout works -
<RibbonWindow ResizeMode="CanResize">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Ribbon Grid.Row="0" />
<ListBox Grid.Row="1"
VerticalAlignment="Stretch"
ScrollViewer.VerticalScrollBarVisibility="Auto"
/>
</Grid>
</RibbonWindow>
Turns out I needed the Grid.Row="x" tags, and then I could remove the StackPanel, and everything worked.

Resources