Si possible, calculer la hauteur de la fenêtre nécessaire lorsque la zone de liste est de 200. Ensuite, il suffit régler la hauteur de la fenêtre à ce numéro comme ceci:
<Window x:Class="WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="225"
Title="MainWindow" >
<DockPanel LastChildFill="True" VerticalAlignment="Stretch">
<TextBlock DockPanel.Dock="Top">Other text</TextBlock>
<ListView BorderBrush="Orange" VerticalAlignment="Stretch" />
</DockPanel>
</Window>
Si cela est impossible, (par exemple, vous n » t savoir à l'avance la taille des autres éléments), puis procédez comme suit:
<Window x:Class="WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" SizeToContent="Height"
Title="MainWindow" Loaded="Window_Loaded" >
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Top">Other Text</TextBlock>
<ListView BorderBrush="Orange" Name="listbox" Height="200" />
</DockPanel>
</Window>
et code derrière:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Height = ActualHeight;
SizeToContent = System.Windows.SizeToContent.Manual;
listbox.Height = Double.NaN;
}
Deuxième solution avec réglage mininal fonctionne pour moi, merci. – ijon