为可写位图命名

Give a name to a writeable bitmap

我想知道有没有办法给可写位图起一个名字

我的文件夹中有 3 张图片。为了在 gridView 中显示它们,我将它们转换为 wrtieableBitmap

if (file.Count > 0)
        {
            var images = new List<WriteableBitmap>();
            foreach (StorageFile f in file)
            {
                var name = f.Name;
                Debug.WriteLine(f.Name);

                ImageProperties properties = await f.Properties.GetImagePropertiesAsync();
                if (properties.Width > 0)
                {
                    var bitmap = new WriteableBitmap((int)properties.Width, (int)properties.Height);

                    Debug.WriteLine(bitmap.PixelWidth);
                    using (var stream = await f.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        bitmap.SetSource(stream);
                    }
                    images.Add(bitmap);
                    Debug.WriteLine(images.Count);
                }
            }

我通过绑定数据将它们添加到 gridView,如 AlGridView.DataContext = images;

现在,一旦我与这些图像进行交互并按下按钮,我就需要保存选择...但是使用带有数字 [1,2,3]

的数组

在转换它们之前,如您在上面看到的,我有一个名称(1.png、2.png 等)但是一旦它们成为可写位图,我就找不到任何方法来提供/ 取个名字

bitmap.SetVale(Name, f.Name);

不起作用,因为它说它不能将字符串转换为 DependencyProperty

有什么想法吗?

哈!我想我找到了解决方案:

properties.Title = name;
var bitmap = new WriteableBitmap((int)properties.Width, (int)properties.Height);
bitmap.SetValue(NameProperty, (string)properties.Title);

谢谢大家!