简体   繁体   中英

How to couple ListBox size to window size, UWP App C#

I am writing a Windows 10 UWP (Universal Windows Platform) app. The app window contains a ListBox and a button. The ListBox should be taking all the space the window offers, and if not all items fit the ListBox, scrollbars should appear.

How can I "couple" the height of the ListBox to eg the window height - 100 ?

The setting the ListBox.Height parameter to this.Height - 100 does unfortunately accomplish nothing, even when done inside a resize event.

Thank you!!

If I understand your question clearly, this is what you need -

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="100" />
    </Grid.RowDefinitions>
    <ListBox />
    <Button Content="Button" HorizontalAlignment="Center" Grid.Row="1" />
</Grid>

You don't need to hard-code the height, instead, you use RowDefinitions to create two rows inside the Grid . The ListBox will occupy the first row and the Button the second row .

Note that the second row has a height of 100epx while the first row simply fills the rest of the space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM