0

There is a task: user selects a folder which has few images. These pictures must be added to the ListBox. I know how to set images to collection List, but I do not know how to dynamically add pictures to ListItem. Give ideas, please !

XAML:

<Grid>
<Grid.RowDefinitions>
    <RowDefinition Height="Auto"></RowDefinition>
    <RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Menu Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center">
    <MenuItem Header="Open" Width="50" Click="MenuItem_Click" FlowDirection="LeftToRight"/>
</Menu>
<ListBox Name="ListBox1" Grid.Row="1" Background="Yellow">            
</ListBox>

C#

public partial class MainWindow : Window
{
     IList<Bitmap> images = new List<Bitmap>();        

     public MainWindow()
     {
         InitializeComponent();
     }

     private void MenuItem_Click(object sender, RoutedEventArgs e)
     {
         var dialog = new System.Windows.Forms.FolderBrowserDialog();
         System.Windows.Forms.DialogResult result = dialog.ShowDialog();            

         if (result == System.Windows.Forms.DialogResult.OK)
         {
            foreach (string file in Directory.GetFiles(dialog.SelectedPath))
            {
                 images.Add(new Bitmap(file));

                 // ListBox1.Items.Add() // I Don't know how to add picture
            }
         }
     }
 }
Spiderman5
  • 23
  • 5

0 Answers0