UWP从WebView拖放到Canvas上

时间:2017-08-30 14:18:09

标签: c# canvas webview uwp

我试过这段代码。我将Image从WebView拖到Canvas。但没有什么可以展示的。也许丢弃的数据是URL或html数据。 BUt我不知道如何将html数据转换为Bitmap数据。

private async void drop(object sender, DragEventArgs e)
{
    if (e.DataView.Contains(StandardDataFormats.StorageItems))
    {
        var items = await e.DataView.GetStorageItemsAsync();
        if (items.Count > 0)
            {
                Point drop = e.GetPosition(Board);
                var storageFile = items[0] as StorageFile;
                var bitmapImage = new BitmapImage();
                bitmapImage.SetSource(await storageFile.OpenAsync(FileAccessMode.Read));

                Image img = new Image();
                img.Source = bitmapImage;
                img.Width = 200;
                img.Height = 150;
                Canvas.SetLeft(img, drop.X);
                Canvas.SetTop(img, drop.Y);
                Board.Children.Add(img);
            }
    }
}

XAML在下面。

<WebView x:Name="WebView" Source="https://google.com" ScriptNotify="Notify" NavigationCompleted="Completed" ></WebView>
<Canvas AllowDrop="True" DragOver="dragOver" Drop="drop"></Canvas>

0 个答案:

没有答案