0

I have this looping intruction (foreach) which reads every image from the "GalleryImages" folder. What I want is to apply a different text for each image. Do I do this with the foreach instruction as well? Do I create a folder where I plce more .txt files?

var files = Directory.GetFiles(@".\GalleryImages");
string text22 = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\WriteText.txt");
foreach (var file in files)
{
    foreach ()
    {
        FileInfo fileInfo = new FileInfo(file);

        WineModel wineModel = new WineModel();
        wineModel.Image = new Uri(file, UriKind.Relative);
        wineModel.Description = text22 + "text text text text text text text text text text text" +
            Environment.NewLine + "text text text text text text text text text text text";
        wineModel.Price = new Random().NextDouble();

        BitmapImage bi = new BitmapImage();
        bi.BeginInit();
        bi.UriSource = wineModel.Image;

        bi.EndInit();

        var button = new KinectTileButton
        {
            Label = System.IO.Path.GetFileNameWithoutExtension(file),
            Background = new ImageBrush(bi),
            Tag = wineModel
        };
        this.wrapPanel.Children.Add(button);
    }
}

I've also posted the code for the click event :

private void KinectTileButtonClick(object sender, RoutedEventArgs e)
{
    var button = (KinectTileButton)e.Source;
    var wineModel = button.Tag as WineModel;
    var selectionDisplay = new SelectionDisplay(wineModel);    
    this.kinectRegionGrid.Children.Add(selectionDisplay);
    e.Handled = true;
}
har07
  • 88,338
  • 12
  • 84
  • 137
  • You want to have descriptions for each image in `GalleryImages`. One possibility is to have txt-file for each image with same name in same or other folder. When you read image file in `foreach` you generate name for description file and read it as well. Other possibility is to store descriptions in one file (it could be database), where you have keys (image file name) and values (description). – Sinatr Apr 11 '14 at 09:21
  • you mean you want to rename your images? – HackerMan Apr 11 '14 at 09:21
  • 3
    You should use the MVVM pattern and bind the `ItemsSource` property of an ItemsControl to an `ObservableCollection` of your WineModel class. Then you would create an appropriate DataTemplate to visualize that data. The [Data Templating Overview](http://msdn.microsoft.com/en-us/library/ms742521.aspx) article an MSDN shows an example of how to do this. – Clemens Apr 11 '14 at 09:28
  • I think it is better to read/write image EXIF data if you perform this operation for only images. Check [here](http://stackoverflow.com/questions/226973/how-to-edit-exif-data-in-net) please – CuriousPen Apr 11 '14 at 09:54
  • So it can be done with a foreach statement inside another statement foreach? – user3522950 Apr 11 '14 at 10:26

0 Answers0