Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How resize a ListBox?

With .net I want to make a ListBox that populates according to a file. The populating goes well, but I can’t go down properly in the ListBox. It goes beyond the height of my window, the problem probably comes from the fact that I’m using the height of the DockPanel. How can I avoid this problem?

<DockPanel x:Name="DockPanel_Color">
    <StackPanel DockPanel.Dock="Right">
        <Label Content="Couleur RGB"/>
        <Border x:Name="Border_SelectedColor" Background="red" Width="100" Height="100" BorderThickness="2" BorderBrush="Black" CornerRadius="10"/>
    </StackPanel>
    <StackPanel x:Name ="test" Margin="5" Height="{Binding ActualHeight, ElementName=DockPanel_Color}">
        <TextBlock>Couleurs</TextBlock>
        <ListBox x:Name="ListBox_Couleurs" SelectionChanged="ListBox_Couleurs_SelectionChanged">
            <ListBox.MaxHeight>
                <Binding Path="ActualHeight" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type DockPanel}}" />
            </ListBox.MaxHeight>
        </ListBox>
    </StackPanel>
</DockPanel>

My Application :

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried without defining a height, with a scrollerViewer, using the height of the "test" StackPanel. But nothing works. And setting a fixed height doesn’t resize the window.

>Solution :

I would try just using another dock panel. The last element in a dock panel fills the remaining space. If you need a scroll bar, just add a ScrollViewer:

<DockPanel x:Name ="test" Margin="5">
        <TextBlock DockPanel.Dock="Top">Couleurs</TextBlock>
        <ScrollViewer HorizontalScrollBarVisibility="Auto">
               <ListBox x:Name="ListBox_Couleurs" SelectionChanged="ListBox_Couleurs_SelectionChanged"/>
        </ScrollViewer>
</DockPanel>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading