如何为每个图像应用不同的文本?

时间:2014-04-11 09:16:28

标签: c# wpf

我有这个循环的指令(foreach),它读取来自" GalleryImages"夹。我想要的是为每个图像应用不同的文本。我是否也使用foreach指令执行此操作?我是否创建了一个文件夹,其中包含更多.txt文件?

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);
    }
}

我还发布了点击事件的代码:

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;
}

0 个答案:

没有答案