Reputation: 520
During developement of some program I've encountered some problems. The first is that I've bound the 'Height' property of listbox control to 'ActualHeight' of my stackPanel. Here's some XAML code I have:
<ListBox Name="listQuotes" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Width="{Binding ElementName=stackPanelQuotes, Path=ActualWidth}"
Height="{Binding ElementName=stackPanelQuotes, Path=ActualHeight}"
ItemsSource="{Binding}" ItemTemplate="{StaticResource quotesFeedTemplate}"
Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
</ListBox>
When I'm expanding my window, size of listbox changes, but when I make it smaller again, the listbox itself doesn't change back, in fact even scrollbar remains the same range... So how am I supposed to get this work properly?
Second thing is that my program consists of two parts - header and the main part Header must remain static, while the the main part (two listboxes in two colums) must resize with the window. By resizing I mean that width should affect both, the header and main part, and height should only affect the main part
Normal view
Corrupted view
And the third thing. How can I make my image resize propotionally (lets say 3:4) whe I'm resing the window (no matter wich - width or height)
Upvotes: 0
Views: 494
Reputation: 1115
You couldget the effect you want by removing the height and width bindings and leaving them as automatic.
<Grid Name="Quotes">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="4*" />
</Grid.ColumnDefinitions>
<ListBox Grid.Column="0" MinWidth="250" Name="listQuotes" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
ItemsSource="{Binding QuotesList}"
Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
</ListBox>
<ListBox Grid.Column ="1" MinWidth="250" Name="listQuotes2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
ItemsSource="{Binding QuotesList}"
Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
</ListBox>
</Grid>
You can get the proportional sizing you want by using a grid with the Columnn definitions I posted. Those will stay in proportion as you resize.
Upvotes: 2