我有一个带有一些图像的列表框。我只想在添加项目时单击刷新按钮后刷新列表框。这是我的代码。
public class img
{
public BitmapImage Imgs { get; set; }
}
public void getImages()
{
try
{
MediaLibrary mediaLibrary = new MediaLibrary();
var pictures = mediaLibrary.Pictures;
foreach (var picture in pictures)
{
BitmapImage image = new BitmapImage();
image.SetSource(picture.GetImage());
img mediaImage = new img();
mediaImage.Imgs = image;
imageList.Items.Add(mediaImage);
}
}
catch (Exception ex)
{
}
}
单击刷新按钮后,我正在调用 get images() ,但它不工作......是否有可能没有可观察的集合。这是我的 xaml==
<ScrollViewer x:Name="Sc" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" Height="550" >
<ListBox Name="imageList" Height="617" HorizontalAlignment="Left" Style="{StaticResource ListBoxStyle1}" SelectionChanged="imageList_SelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Imgs}" Width="100" Height="100"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>