1
我越来越空白图像列表框,图像源的不具约束力我想......图像绑定到列表框在WPF
的.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;
这里我试图将图像绑定到列表框图像源不是绑定它显示列表框中的空图像。
您创建的FileInfo对象的ArrayList,并期待它来向您展示UI图像,你希望是什么?也没有任何绑定和图像控制。 – Nitesh
你真的只想显示带有大写文件扩展名的图片吗,比如'.PNG'? – Clemens
@Nitesh实际上有一个带有“Source =”{Binding}“绑定的图像控件。但它不会工作。 – Clemens