Set height of element to height of neighbouring element - c#

I have a GUI in WPF application which looks like that:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Width="100" Height="50" Margin="2"></Border>
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Width="100" Height="90" Margin="2"></Border>
</StackPanel>
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Margin="2">
<StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="Some"/>
<Button Content="Buttons"/>
</StackPanel>
<Label Content="Some Label"/>
<ListView ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListViewItem>Item1</ListViewItem>
<ListViewItem>Item2</ListViewItem>
<!-- and so on...-->
<ListViewItem>Item8</ListViewItem>
</ListView>
</StackPanel>
</Border>
</StackPanel>
</Grid>
The two borders to the left are just placeholders for the GUI elements in the real application. The GUI element looks like this:
I want the right StackPanel to be just as high as the left StackPanel, like in the following screenshot:
For the screenshot, I was manually setting the MaxHeight property of the ListView to right value, but of course that is no satisfying solution and it will become impossible if I don't know at compile time which and how many elements populate the left StackPanel.
Is there any solution to this Problem? I was trying a binding:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical" Name="Left">
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Width="100" Height="50" Margin="2"></Border>
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Width="100" Height="90" Margin="2"></Border>
</StackPanel>
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Margin="2" Height="{Binding ElementName=Left, Path=Height}">
<!-- as above -->
</Border>
</StackPanel>
</Grid>
But I did not succeed with it, also when I bind to the ActualHeight of the left StackPanel. Any suggestions?

Stack panels expand to fit their contents. Instead you need to put the ListView in a container of a fixed size (I've used a Grid with a row of height *), that takes its size from the boxes in the first column.
I used a binding to ActualHeight, that was very similar to yours.
The other important difference was setting VerticalAlignment="Top" on the first stack panel, otherwise it automatically sizes to the same height as the border.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical" Name="Left" VerticalAlignment="Top">
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Width="100" Height="50" Margin="2"></Border>
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Width="100" Height="90" Margin="2"></Border>
</StackPanel>
<Border Height="{Binding ElementName=Left, Path=ActualHeight}" >
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Margin="2">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button Content="Some"/>
<Button Content="Buttons"/>
</StackPanel>
<Label Grid.Row="1" Content="Some Label"/>
<ListView Grid.Row="2" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListViewItem>Item1</ListViewItem>
<ListViewItem>Item2</ListViewItem>
<ListViewItem>Item2</ListViewItem>
<ListViewItem>Item2</ListViewItem>
<ListViewItem>Item2</ListViewItem>
<ListViewItem>Item2</ListViewItem>
<!-- and so on...-->
<ListViewItem>Item8</ListViewItem>
</ListView>
</Grid>
</Border>
</Border>
</StackPanel>
</Grid>

<StackPanel>
<Grid Width="300" Height="200">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>
<Border Background="Beige" BorderThickness="1" BorderBrush="Black" Margin="2"></Border>
<Border Grid.Row="1" Background="Beige" BorderThickness="1" BorderBrush="Black" Margin="2"></Border>
</Grid>
<Border Grid.Column="1" Background="Beige" BorderThickness="1" BorderBrush="Black" Margin="2">
<StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="Some"/>
<Button Content="Buttons"/>
</StackPanel>
<Label Content="Some Label"/>
<ListView ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListViewItem>Item1</ListViewItem>
<ListViewItem>Item2</ListViewItem>
<!-- and so on...-->
<ListViewItem>Item8</ListViewItem>
</ListView>
</StackPanel>
</Border>
</Grid>
</StackPanel>

Try this:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel
Name="FirstPanel"
Grid.Column="0"
VerticalAlignment="Top">
<Border
Background="Beige"
BorderThickness="1"
BorderBrush="Black"
Width="100"
Height="50"
Margin="2"/>
<Border
Background="Beige"
BorderThickness="1"
BorderBrush="Black"
Width="100"
Height="90"
Margin="2"/>
</StackPanel>
<Border
Name="ContainerBorder"
Grid.Column="1"
Background="Beige"
BorderThickness="1"
BorderBrush="Black"
Margin="2"
VerticalAlignment="Top"
MaxHeight="{Binding ElementName=FirstPanel, Path=ActualHeight}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button Content="Some"/>
<Button Content="Buttons"/>
</StackPanel>
<Label Grid.Row="1" Content="Some Label"/>
<ListView Grid.Row="2" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListViewItem>Item1</ListViewItem>
<ListViewItem>Item2</ListViewItem>
<ListViewItem>Item3</ListViewItem>
<ListViewItem>Item4</ListViewItem>
<ListViewItem>Item5</ListViewItem>
<ListViewItem>Item6</ListViewItem>
<ListViewItem>Item7</ListViewItem>
<ListViewItem>Item8</ListViewItem>
</ListView>
</Grid>
</Border>
</Grid>
Output:

Related

Vertical scrollbar for a listview within an expander

I have a grid(user-control) as follows with rows 1:5 being an Expander which holds a ListView, however my attempts to get the Vertical scrollbar for the ListView within the Expander have not been successful.
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="*"></RowDefinition> <!--Expander with ListView-->
<RowDefinition Height="*"></RowDefinition> <!--Expander with ListView-->
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
The Expander with the ListView is as below, I also attempted enclosing the Expander within a ScrollViewer but then the sizing of the collapsed header takes up all the space
<Expander IsExpanded="True"
Background="#1F4762"
BorderBrush="#1F4762"
Foreground="#FFEEEEEE"
Grid.Row="1"
Visibility="{qc:Binding '$P.View.Count > 0 ? Visibility.Visible: Visibility.Collapsed', P={Binding AListCVS}}"
BorderThickness="1,1,1,0">
<Expander.Header>
<TextBlock FontWeight="Bold"
VerticalAlignment="Center"
Margin="5"
FontSize="14"
Width="200">
<Run Text="A Listers : " />
<Run Text="{Binding AListCVS.View.Count, Mode=OneWay}"></Run>
</TextBlock>
</Expander.Header>
<Expander.Content>
<ListView
HorizontalContentAlignment="Stretch"
AlternationCount="2"
Style="{StaticResource aCompareTemplate}"
ItemTemplateSelector="{StaticResource ATemplateSelector}"
x:Name="lview"
ItemsSource="{Binding AListCVS.View}"
Visibility="{Binding }">
</ListView>
</Expander.Content>
</Expander
The list template is as follows
<Style x:Key="aCompareTemplate"
TargetType="ListView">
<!--Control Template-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0"
MinWidth="900"
VerticalAlignment="Center"
Background="#D4E3F4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition MinWidth="200"></ColumnDefinition>
<ColumnDefinition MinWidth="400"></ColumnDefinition>
<ColumnDefinition Width="200*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Column="0"
Height="30">
<TextBlock Text=""
FontWeight="Bold"
VerticalAlignment="Center"
HorizontalAlignment="Center"
TextWrapping="Wrap" />
</Border>
<Border Grid.Column="1"
Height="30">
<TextBlock Text=""
FontWeight="Bold"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
</Border>
<Border Grid.Column="2"
Height="30">
<TextBlock Text="A Data"
FontWeight="Bold"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
</Border>
<Border Grid.Column="3"
Height="30">
<TextBlock Text="B Data"
FontWeight="Bold"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
</Border>
</Grid>
<ItemsPresenter Grid.Row="1"></ItemsPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
Any pointers are much appreciated.
Usually the problem with Scroll is due to the container in which it is inserted allow infinite size, and therefore it does not appear. Possibly you can correct this by setting a MaxHeight to your Grid.Row, or to your ListView.
Edit.: as was suggested by #FelixD. and as my above comment helped to solve the problem I am putting it here so the question can be marked as resolved.

UWP C# - Problems with Grid in a Listview

I am writing a little app in C# for windows 10, and I have a listview as below, which is already in a grid.
However the grid I am adding to the listview doesn't expand out to fill the space, it is just grows as wide as the length of the data contained in the field bound to it. What am I doing wrong? I don't want to use fixed fields, I'd prefer to use a relative proportion of the page width.
Help!
<Grid x:Name="RootGrid" Margin="5" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="FolderMate" Style="{StaticResource SampleHeaderTextStyle}"/>
<Button x:Name="GetFilesAndFoldersButton"
Grid.Row="1"
Grid.Column="0"
Content="Get files and folders"
Click="GetFilesAndFoldersButton_Click"
Margin="0,10,0,10"/>
<TextBlock x:Name="FileInfo"
Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="3"
VerticalAlignment="Center"
Margin="10"
Foreground="Green"/>
<Button x:Name="ResetButton"
Grid.Row="1"
Grid.Column="5"
Content="reset"
HorizontalAlignment="Right"
Click="ResetButton_Click"
Margin="0,10,10,0"/>
<!--<ScrollViewer VerticalScrollMode="Auto"
VerticalScrollBarVisibility="Auto"
Grid.Row="2"
Grid.ColumnSpan="5"
BorderBrush="Black"
BorderThickness="2"
Background="Chartreuse"
Margin="0,5,0,5">-->
<ListView x:Name="ThisList"
Grid.Row="2"
Grid.ColumnSpan="5"
Background="LightBlue"
Margin="5"
IsItemClickEnabled="True"
ItemClick="ThisList_ItemClick">
<ListView.ItemTemplate>
<DataTemplate>
<Grid BorderThickness="1" BorderBrush="Red" >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Background="Aquamarine" Grid.Column="0">
<SymbolIcon Symbol="Folder" HorizontalAlignment="Center" Margin="15 0"/>
</Border>
<Border Background="Yellow" Grid.Column="1">
<TextBlock Text="{Binding FName}" Margin="10" />
</Border>
<Border Background="Cyan" Grid.Column="2">
<TextBlock Text="{Binding FTime}" Margin="10"/>
</Border>
<Border Background="Tomato" Grid.Column="3">
<TextBlock Text="{Binding FSize}" HorizontalAlignment="Right" Margin="10"/>
</Border>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!--</ScrollViewer>-->
</Grid>
You need to set the HorizontalContentAlignment inside ListView.ItemContainerStyle for ListViewItem to Stretch.
Your Full XAML For ListView will be like below.
<ListView x:Name="ThisList"
Grid.Row="2"
Grid.ColumnSpan="5"
Background="LightBlue"
Margin="5"
ItemsSource="{Binding data}"
IsItemClickEnabled="True"
ItemClick="ThisList_ItemClick">
<ListView.ItemTemplate>
<DataTemplate>
<Grid BorderThickness="1" BorderBrush="Red" >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Background="Aquamarine" Grid.Column="0">
<SymbolIcon Symbol="Folder" HorizontalAlignment="Center" Margin="15 0"/>
</Border>
<Border Background="Yellow" Grid.Column="1">
<TextBlock Text="{Binding FName}" Margin="10" />
</Border>
<Border Background="Cyan" Grid.Column="2">
<TextBlock Text="{Binding FTime}" Margin="10"/>
</Border>
<Border Background="Tomato" Grid.Column="3">
<TextBlock Text="{Binding FSize}" HorizontalAlignment="Right" Margin="10"/>
</Border>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
See in the end, How I added ItemContainerStyle Targeting Only ListViewItem.
Final Output will be
Good Luck.
Might be it will helpful for you. I had used like that-
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto">
<StackPanel>
<ListView x:Name="UserMessageList">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local1:MessageModel">
<StackPanel>
//Add your conrole
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</ScrollViewer>

Resize Scrollviewer and StackPanel WPF C#

how can I make the scrollviewer resize to the bottom edge of the screen, so as to maximize to resize with the mouse ? The way the code is, when the screen is maximized the scroll bar does not appear and it is not possible to scroll the contents.
My xaml File
<Window x:Class="AppSearch.MainWindow" x:Name="mainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AppSearch" Height="600" Width="820"
WindowStartupLocation="CenterScreen"
Loaded="Window_Loaded"
StateChanged="mainWindow_StateChanged"
ResizeMode="CanResize"
PreviewKeyDown="mainWindow_PreviewKeyDown">
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="stkContentLeft"
MinWidth="510"
MinHeight="560"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
LoadCompleted="stkContentLeft_LoadCompleted"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Margin="0,0,05,0" Grid.Column="0"/>
<StackPanel Grid.Column="1" x:Name="stckContentRight" Width="276"
Height="{Binding Parent.ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
Orientation="Vertical"
HorizontalAlignment="Right">
<Grid VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Height="auto" Grid.Row="0">
<StackPanel x:Name="help" Width="20" Height="20" HorizontalAlignment="Right" Margin="0,5,10,0">
<Image Source="Imagens/help_icon.png"/>
</StackPanel>
<StackPanel x:Name="stkUcSupervisor" Height="50" Width="276" Margin="0,5,0,0" HorizontalAlignment="Center"/>
<TextBox x:Name="txtSearch"
ToolTip="put your key..."
FontSize="13"
Foreground="Black"
BorderThickness="1"
TextWrapping="Wrap"
Margin="0,5,0,05" Width="270" HorizontalAlignment="Center"/>
</StackPanel>
<ScrollViewer x:Name="scroll"
CanContentScroll="True"
IsDeferredScrollingEnabled="False"
UseLayoutRounding="False"
VerticalScrollBarVisibility="Visible"
VerticalAlignment="Top"
BorderThickness="1"
BorderBrush="Gray"
Margin="0,05,0,0"
Grid.Row="1"
Height="455">
<StackPanel x:Name="stkListOfUserControls"
CanVerticallyScroll="True"
Height="455"
OverridesDefaultStyle="False">
<StackPanel.ScrollOwner>
<ScrollViewer AllowDrop="True" />
</StackPanel.ScrollOwner>
</StackPanel>
</ScrollViewer>
</Grid>
</StackPanel>
<StackPanel x:Name="stkPopUp"
Canvas.Bottom="0"
Canvas.Left="0"
Height="285"
Width="280"
VerticalAlignment="Bottom"/>
</Grid>

Silverlight - TabControl refusing to fill remaining space

At my wits end with trying to get a TabControl and TabItems to fill a NavigationPage/Frame.
I have a MasterPage, with a Frame, that will get swapped out for different Pages, which are comprised of UserControls.
The problem I am having is that the TabControl is cutting off the UserControl and not auto sizing properly. Below is an image and the source for the Pages and Controls.
[Field below Location is cutoff] http://imgur.com/FoDGJyN
MainPage.xaml
<UserControl x:Class="TournamentControls.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:navigation="clr-
namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:uriMapper="clr-
namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="800">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Name="topNavi" Orientation="Horizontal" Grid.Row="0">
<TextBlock Name="TournamentsNavi" Text="Tournaments"
MouseLeftButtonUp="TournamentsNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="DivisonsNavi" Text="Division"
MouseLeftButtonUp="DivisonsNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="EventsNavi" Text="Events"
MouseLeftButtonUp="EventsNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="CompetitorsNavi" Text="Competitors"
MouseLeftButtonUp="CompetitorsNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="MastersNavi" Text="Masters"
MouseLeftButtonUp="MastersNavi_MouseLeftButtonUp" Margin="0,0,20,0"/>
<TextBlock Name="RefereesNavi" Text="Referees"
MouseLeftButtonUp="RefereesNavi_MouseLeftButtonUp"/>
</StackPanel>
<navigation:Frame x:Name="PageContent" Background="#007A0909" Grid.Row="1"
Navigated="PageContent_Navigated" Navigating="PageContent_Navigating">
<navigation:Frame.UriMapper>
<uriMapper:UriMapper>
<uriMapper:UriMapping Uri="/{pageName}"
MappedUri="/Pages/{pageName}.xaml"/>
</uriMapper:UriMapper>
</navigation:Frame.UriMapper>
</navigation:Frame>
</Grid>
</UserControl>
TournamentsPage.xaml
<navigation:Page x:Class="TournamentControls.Tournaments"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-
namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:toolkit2="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:cc="clr-namespace:TournamentControls.Controls.Tournaments"
d:DesignWidth="640" d:DesignHeight="480" Title="Tournaments Page">
<Grid x:Name="LayoutRoot" Background="White">
<toolkit2:TabControl>
<toolkit2:TabItem x:Name="CreateTab" Header="Create Tournament">
<cc:TournamentsCreateControl/>
</toolkit2:TabItem>
<toolkit2:TabItem x:Name="ModifyTab" Header="Modify Tournament">
<cc:TournamentsModifyControl/>
</toolkit2:TabItem>
</toolkit2:TabControl>
</Grid>
</navigation:Page>
TournamentsCreateControl.xaml
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Margin="0,4,0,4" Style="{StaticResource TaskGridMenuBarBorderStyle}" Grid.ColumnSpan="2" >
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Border Style="{StaticResource TaskGridMenuBorderStyle}" Margin="0,0,25,0" Padding="10,0" Grid.ColumnSpan="1" HorizontalAlignment="Left">
<StackPanel x:Name="pnlTaskGridToolbar" Orientation="Horizontal">
<!-- save -->
<Button x:Name="SaveButton" Style="{StaticResource ImageButtonStyle}"
Click="SaveButton_Click" ToolTipService.ToolTip="Save BMC Structure" Margin="0,0,5,0" >
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="../../Resources/Icons/Save.png" Margin="0,0,2,0" />
<TextBlock VerticalAlignment="Center">Save Tournament</TextBlock>
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</Border>
</Grid>
</Border>
<Grid x:Name="ContentGrid" Grid.Row="1" VerticalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" x:Name="LabelsSP" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,5,0,10">
<TextBlock x:Name="TournamentLbl" Text="Tournament Name:" FontWeight="Bold" Margin="0,0,10,0" VerticalAlignment="Center"/>
<TextBox x:Name="TournamentTbx" Width="100" MaxLength="255"/>
</StackPanel>
<StackPanel Grid.Row="1" x:Name="LocationSP" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,0,10">
<TextBlock x:Name="LocationLbl" Text="Location:" FontWeight="Bold" Margin="60,0,12,0" VerticalAlignment="Center"/>
<TextBox x:Name="LocationTbx" Width="100" MaxLength="255"/>
</StackPanel>
<StackPanel Grid.Row="2" x:Name="DateTimeSP" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,0,10">
<TextBlock x:Name="DateTimeLbl" Text="Tournament Time:" FontWeight="Bold" Margin="3,0,12,0" VerticalAlignment="Center"/>
<toolkit2:DatePicker x:Name="DateTimePicker"/>
</StackPanel>
<StackPanel x:Name="ButtonSP" Orientation="Horizontal"/>
</Grid>
</Grid>
</Grid>
TournamentsModifyControl.xaml
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Margin="0,4,0,4" Style="{StaticResource TaskGridMenuBarBorderStyle}" Grid.ColumnSpan="2" >
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition/>
</Grid.RowDefinitions>
<Border Style="{StaticResource TaskGridMenuBorderStyle}" Margin="0,0,25,0" Padding="10,0" Grid.ColumnSpan="1" HorizontalAlignment="Left">
<StackPanel x:Name="pnlTaskGridToolbar" Orientation="Horizontal">
<!-- save -->
<Button x:Name="SaveButton" Style="{StaticResource ImageButtonStyle}"
Click="SaveButton_Click" ToolTipService.ToolTip="Save Tournament Changes" Margin="0,0,5,0" >
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="../../Resources/Icons/Save.png" Margin="0,0,2,0" />
<TextBlock VerticalAlignment="Center">Save Tournament Changes</TextBlock>
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</Border>
</Grid>
</Border>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" x:Name="TournamentsSelectSP" Orientation="Horizontal" Margin="0,5,0,10">
<TextBlock x:Name="CurrentTournamentsLbl" Text="Current Tournaments:" FontWeight="Bold" VerticalAlignment="Center" Margin="0,0,10,0"/>
<ComboBox x:Name="CurrentTournamentsCbx"/>
</StackPanel>
<StackPanel Grid.Row="1" x:Name="LabelsSP" Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock x:Name="TournamentLbl" Text="Tournament Name:" FontWeight="Bold" Margin="0,0,10,0" VerticalAlignment="Center"/>
<TextBox x:Name="TournamentTbx" Width="100" MaxLength="255"/>
</StackPanel>
<StackPanel Grid.Row="2" x:Name="LocationSP" Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock x:Name="LocationLbl" Text="Location:" FontWeight="Bold" Margin="60,0,12,0" VerticalAlignment="Center"/>
<TextBox x:Name="LocationTbx" Width="100" MaxLength="255"/>
</StackPanel>
<StackPanel Grid.Row="3" x:Name="DateTimeSP" Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock x:Name="DateTimeLbl" Text="Tournament Time:" FontWeight="Bold" Margin="3,0,12,0" VerticalAlignment="Center"/>
<toolkit2:DatePicker x:Name="DateTimePicker"/>
</StackPanel>
</Grid>
</Grid>

StackPanel in Grid: limit height

I have a big main grid with several rows and columns. I want to place in one of these cells a vertical stackpanel. In this stackpanel there is a textblock and a scrollviewer. My problem is, that the stackpanel doesn't get limited by the cell, instead the stackpanel gets big enough to fit the whole scrollviewer.
How can I solve this?
EDIT: my xaml code:
<Grid x:Name="Grid1" Margin="120,0,0,0" Width="1244">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0*"/>
<ColumnDefinition Width="33*"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="71"/>
<RowDefinition Height="40"/>
<RowDefinition/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="3" Grid.Row="2" Grid.ColumnSpan="2" Margin="0">
<TextBlock TextWrapping="Wrap" FontSize="48" Margin="0" VerticalAlignment="Top" Foreground="#FF0083FF" Text="Top 10:" HorizontalAlignment="Left" FontFamily="Segoe UI Light"/>
<ScrollViewer Margin="0,20,0,0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible">
<StackPanel>
<ListView x:Name="TopListView" ItemsSource="{Binding}" SelectionMode="None" Foreground="White" >
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel >
<TextBlock FontSize="32" Text="1" Foreground="#FF0083FF"/>
</StackPanel>
<TextBlock Text="{Binding Text}" Foreground="Black"
FontSize="16" Margin="0,0,0,0" TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Grid>
Use another Grid instead of a StackPanel:
<Grid Grid.Column="3" Grid.Row="2" Grid.ColumnSpan="2" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock FontSize="48" FontFamily="Segoe UI Light"
Foreground="#FF0083FF" HorizontalAlignment="Left"
TextWrapping="Wrap" Text="Top 10:"/>
<ScrollViewer Grid.Row="1" Margin="0,20,0,0"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Visible">
...
</ScrollViewer>
</Grid >

Categories

Resources