【发布时间】:2019-06-27 04:45:26
【问题描述】:
列表框项的图片太大。enter image description here
我想让它成为一个恒定高度的项目。就像下图一样。 enter image description here
这是我的代码
xaml:
<ListBox Grid.Row="0" x:Name="listBox" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" AllowDrop="True" Drop="ListBox_Drop" DragEnter="ListBox_DragEnter" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Image Margin="3" Source="{Binding Path}"/>
<TextBlock Margin="3" Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
cs:
class VideoListing
{
public string Name { get; set; }
public string Path { get; set; }
}
List<VideoListing> list = new List<VideoListing>();
public VideoPanel()
{
InitializeComponent();
list.Add(new VideoListing()
{
Name = "hello",
Path = @"C:\Users\jskae\Desktop\Screenshot.png",
});
listBox.Items.Add(list);
}
【问题讨论】:
-
您的目标是什么:Winforms、WPF、ASP..?您应该始终正确标记您的问题,以便人们可以在问题页面上看到它!
-
@TaW 谢谢,我更改了问题标题。
-
WPF 不应出现在标题中。应该是标签! (已更改)
标签: c# image text listbox wpf-controls