wabbajack/Wabbajack.Lib/WebAutomation/WebAutomationWindowViewModel.cs
2019-10-24 21:02:32 -06:00

40 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
using Microsoft.Toolkit.Wpf.UI.Controls;
namespace Wabbajack.Lib.WebAutomation
{
public class WebAutomationWindowViewModel : ViewModel
{
private WebAutomationWindow _window;
private WebView Browser => _window.WebView;
public WebAutomationWindowViewModel(WebAutomationWindow window)
{
_window = window;
}
public Task<Uri> NavigateTo(Uri uri)
{
var tcs = new TaskCompletionSource<Uri>();
EventHandler<WebViewControlNavigationCompletedEventArgs> handler = null;
handler = (s, e) =>
{
Browser.NavigationCompleted -= handler;
tcs.SetResult(uri);
};
Browser.NavigationCompleted += handler;
Browser.Source = uri;
return tcs.Task;
}
}
}