在我的地铁应用中,我想上传image
。实际上在button-click
上,应该打开文件浏览器并提示图像。当用户选择任何图像时,我想使用view
标记在image
中显示它,并将其保存在服务器端。我有以下图片和按钮代码:
<Border Margin="0,30,0,0" BorderThickness="2" BorderBrush="#FFAAA7A7" HorizontalAlignment="Center" Height="113">
<Image Height="101" Source="temp.png" Margin="0,-2,0,10"/>
</Border>
<AppBarButton HorizontalAlignment="Center" Label="Upload Image" VerticalAlignment="Center" Icon="Camera" Width="178" Margin="0,0,0,0" Click="AppBarButton_Click" />
答案 0 :(得分:1)
您正在搜索FilePicker对话框。 Here是关于它的好文章。以下代码执行:
此代码取自页面:
if (rootPage.EnsureUnsnapped())
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write access to the picked file
//OutputTextBlock.Text = "Picked photo: " + file.Name;
}
else
{
//OutputTextBlock.Text = "Operation cancelled.";
}
}