WPF ListBox 行高

3
我在wpf中创建了一个listbox,并在点击按钮时动态添加项目。我想知道如何将列表框中每一行的总高度设置为特定值?
我在网上搜索到了一个类似的例子,但我不确定如何将这个解决方案整合到我的代码中。希望有人能帮忙。谢谢大家。
参考链接:如何设置WPF ListView行高?
<Window x:Class="stadio.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Stadio" Height="350" Width="525" Background="#FF212121">
    <Grid>
        <ListBox x:Name="uiFileList" BorderThickness="0" Background="{x:Null}" Foreground="Gainsboro" Margin="6"/>

    </Grid>
</Window>
1个回答

12

应该与您找到的示例非常相似,该示例演示了相同的内容,但使用listview。 您只需要将 ListView... 更改为 ListBox...

<ListBox x:Name="uiFileList" BorderThickness="0" 
         Background="{x:Null}" Foreground="Gainsboro" 
         Margin="6">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="Height" Value="50" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接