我在列表框中得到空白图像,我认为图像源未绑定...
.xaml 代码:
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel FlowDirection="LeftToRight" ItemWidth="120" ItemHeight="120"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button x:Name="b" Click="b_Click_1" Width="120" Height="120" >
<Image HorizontalAlignment="Left"
Margin="-10,-10,-10,-10"
x:Name="image1"
Stretch="Fill"
VerticalAlignment="Top" Source="{Binding}"
/>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
` .cs 代码:
DirectoryInfo dir = new DirectoryInfo(@"C:\Users\sandeep ams\Documents\Images");
FileInfo[] file = dir.GetFiles();
ArrayList list = new ArrayList();
foreach (FileInfo file2 in file)
{
if (file2.Extension == ".JPG" || file2.Extension == ".JPEG" || file2.Extension == ".GIF" || file2.Extension == ".PNG")
{
list.Add(file2);
}
}
listBox.ItemsSource = list;
在这里,我试图将图像绑定到列表框图像源未绑定它在列表框中显示空图像。