I have an ScrollViewer that I am trying to do data binding on the height of. The ScrollViewer holds a long ListBox
So here is my question. My ScrollViewer will bind to the height of my window (Name="MainForm"
) just fine. But then it is too long.
If I try to bind to a grid in the window (Name="MainGrid"
) then the ScrollViewer expands to the full length of the listbox (no scrolling).
Obviously I could hard code the height, but then it will not resize with the window. A feature that I do not want to loose.
Any Ideas?
This is the xaml with the binding set to MainGrid
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WI Assistant" Height="621.25" Width="943.75" Name="MainForm" FontSize="14">
<Grid Name="MainGrid">
<DockPanel Margin="266.25,0,455,12" HorizontalAlignment="Left" Name="dockPanel1">
<StackPanel>
<ScrollViewer Height="{Binding ElementName=MainGrid, Path=Height}">
<ListBox Name="cboProjects" FontSize="14" >
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem>
</ListBox>
</ScrollViewer>
</StackPanel>
</DockPanel>
</Grid>
(This will run (F5) in XamlPadx)