WPF页面中的ListBox在我的PC上看起来很好,但数据在较小的分辨率上缩小

时间:2013-02-07 23:28:45

标签: wpf xaml listbox alignment

我几乎尝试了所有路线和边距的组合,但没有成功。 ListBox位于WPF页面上,该页面绑定到主窗口上的框架。

ListBox本身很好。它正如我预期的那样对齐。我的ListBoxItem包含一个Image和一个TextBlock。 TextBlock被切断了。

从下图中可以看出,事情基本上都很好。

enter image description here

ListBox与该蓝色框的左边缘和顶部适当偏移。内容Image和TextBlock相当居中,ListBoxItem大纲也是如此。这是在我的开发机器上。

我认为使用网格,网格线和对齐属性的全部原因是我们不必设置硬编码大小。我们的控件会调整自己的大小。哪个实际上对其他一切都很好。

但是当我把它放在一个小屏幕上时,我明白了:

enter image description here

ListBox本身仍然正确对齐。但现在ListBoxItem被强制关闭了。它的顶部对齐仍然很好,但是底部被推下,所以我们看不到TextBlock或ListBoxItem的底部。

这是我的XAML:

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="1">
    <Grid.RowDefinitions>
        <RowDefinition Height="292*" />
        <RowDefinition Height="30*"/>
    </Grid.RowDefinitions>

    <ListBox Grid.Row="1" Name="lbButtons" Margin="2,0,0,1.5" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Visibility="Visible" >
        <StackPanel Name="spListBoxItems" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal">
            <ListBoxItem Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
                <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="10,5,10,5">
                    <Image Source="/COBAN.CobanConsole.UI;component/Images/Buttons/Light/record48_light.png" />
                    <TextBlock Text="Record" Margin="5,5,0,0"></TextBlock>
                </StackPanel>
            </ListBoxItem>
        </StackPanel>
    </ListBox>
</Grid>

不多。关于发生了什么的任何想法?

1 个答案:

答案 0 :(得分:0)

您在网格行定义中使用*单位。这些是相对的衡量标准:它们只是告诉你行可占用的空间比例。如果您需要列表框具有特定高度,则应将第二行更改为具有绝对大小,如下所示:

<Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="30"/>
</Grid.RowDefinitions>
相关问题