Windows Phone ListBox项的高度 [英] Windows Phone ListBox item height

查看:55
本文介绍了Windows Phone ListBox项的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多答案,却找不到答案.
所以:我正在制作一个Windows Phone应用程序(目标是7.1),并且我有一个带有以下ItemTemplate的ListBox

I've searched a lot for an answer and couldn't find one.
So: I'm making a Windows Phone app (targeting 7.1) and I have a ListBox with the following ItemTemplate

<ListBox.ItemTemplate>
    <DataTemplate>
        <Grid>
            <TextBlock x:Name="subjectName" Text="{Binding Path=name}" TextWrapping="Wrap" Foreground="White" FontSize="30" FontFamily="Segoe WP Semibold" Width="440" Height="99"/>
            <TextBlock x:Name="subjectCode" Text="{Binding Path=code}" FontSize="25" Width="107" HorizontalAlignment="Right" Margin="0,79,0,-12"/>
            <TextBlock x:Name="totalAbsences" Text="{Binding Path=absences}" FontSize="30" Width="107" HorizontalAlignment="Left" Margin="0,119,0,-65"/>
            <TextBlock x:Name="totalGrade" Text="{Binding Path=grades}" FontSize="30" Width="186" HorizontalAlignment="Right" Margin="0,119,0,-62" TextAlignment="Right"/>
            <Rectangle Fill="White" Height="3" Margin="0,0,0,-233" />
        </Grid>
    </DataTemplate>
</ListBox.ItemTemplate>

这就是发生的事情:

http://d.pr/i/liBK (无法在此处发布图片)

http://d.pr/i/liBK (can't post images here yet)

那该怎么做才能自动调整物品的高度?

So what can be done so that the item's height is adjusted automatically?

推荐答案

由于列表框中的每个项目都包含在Grid中,因此您可以指定 Grid.RowDefinitions 并在网格具有特定的行号.

Since each item in the listbox is enclosed in a Grid, you can specify Grid.RowDefinitions and assign each of the children in the Grid to have a certain Row number.

示例:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition> <!-- Gets whatever height is necessary -->
        <RowDefinition Height="140"></RowDefinition> <!-- Specific Height -->
        <RowDefinition MaxHeight="*"></RowDefinition> <!-- Fills whatever space is left -->
    </Grid.RowDefinitions>
    <TextBlock x:Name="subjectName" Text="{Binding Path=name}" Grid.Row="0"/>
    <TextBlock x:Name="subjectCode" Text="{Binding Path=code}" Grid.Row="1"/>
    <TextBlock x:Name="totalAbsences" Text="{Binding Path=absences}" Grid.Row="2"/>
</Grid>

为了简单起见,我使用了一些代码,并删除了一些额外的属性.随便看看吧,看看有什么用.

I used some of your code and removed some extra properties for the sake of simplicity. Just play around with it and see what works.

这篇关于Windows Phone ListBox项的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆