【发布时间】:2014-12-26 07:43:50
【问题描述】:
我们正在开发一个应用程序,该应用程序必须在运行时附加图像并将其显示到 UI。我们正在使用以下一组代码文件:
private void Btn_Attach_File_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.FileTypeFilter.Add(".jpg");
fileOpenPicker.FileTypeFilter.Add(".jpeg");
fileOpenPicker.FileTypeFilter.Add(".png");
fileOpenPicker.ContinuationData["Operate"] = "OpenImage";
fileOpenPicker.PickSingleFileAndContinue();
}
另外,要在从存储中选择文件后继续应用,这里是代码:
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
{
if ((args.Files != null && args.Files.Count > 0))
{
IReadOnlyList<StorageFile> files = args.Files;
Image myImage = new Image();
foreach (StorageFile file in files)
{
if (args.ContinuationData["Operate"] as string == "OpenImage" && args.Files != null && args.Files.Count > 0)
{
IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
System.Diagnostics.Debug.WriteLine(file.Name);
System.Diagnostics.Debug.WriteLine(file.Path);
using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 190)) //, ThumbnailOptions.UseCurrentScale);
{
if (thumbnail != null && thumbnail.Type == ThumbnailType.Image)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(thumbnail);
myImage.Source = bitmapImage;
}
}
}
}
}
}
以上代码在 xaml.cs 文件中。 但问题是,即使我正在加载文件,UI 上也没有附件。 我们是否需要对相应的 xaml 文件进行任何更改?我们搜索了很多,但找不到任何解决方案。
提前致谢,
【问题讨论】:
-
您能否向我们展示您将图像设置为某些 UI 控件的代码?
-
我想我缺少 UI 控件的图像设置。 RenDishen,你能解释一下怎么做吗?谢谢。
标签: c# wpf xaml windows-phone-8