Hello,
I'm using WebView2 in content of DocumentWindow/ToolWindow.
When I tried to switch active window from modal window, below exception occured.
Would you please tell me the workaround?
Is this problem of WebView2 side?
Exception
System.ArgumentException
HResult=0x80070057
Message=Value does not fall within the expected range.
Source=Microsoft.Web.WebView2.Core
Stack trace:
at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON reason)
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.MoveFocus(CoreWebView2MoveFocusReason reason)
at Microsoft.Web.WebView2.Wpf.WebView2.TabIntoCore(TraversalRequest request)
at ActiproSoftware.Internal.NH.LXA(UIElement )
at ActiproSoftware.Internal.NH.aXR(UIElement )
at ActiproSoftware.Internal.NH.<>c__DisplayClass7_0.K88()
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.ShowDialog()
at ActiproSoftware.ProductSamples.DockingSamples.Demo.SimpleIde.MainControl.OnSubWindowMenuClick(Object sender, RoutedEventArgs e) in C:\Users\[User Name]\Documents\Actipro Software\WPF-Controls\v21.1.3\SampleBrowser\ProductSamples\DockingSamples\Demo\SimpleIde\MainControl.xaml.cs:line 606
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at ActiproSoftware.SampleBrowser.App.Main()
My sample source code
(based on SampleBrowser\ProductSamples\DockingSamples\Demo\SimpleIde)
MainControl.xaml(1)
- Add ToolWindow contains WebView2 to ToolWindowContainer.
<sampleBrowser:ProductItemControl
~~
namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
~~~~
>
<docking:ToolWindowContainer>
<docking:ToolWindow
x:Name="WebView2ToolWindow"
Title="WebView2">
<wv2:WebView2 docking:InteropFocusTracking.IsEnabled="True" Source="https://www.microsoft.com" />
</docking:ToolWindow>
~~~~
SubWindow.xaml (Create new)
<Window
x:Class="ActiproSoftware.ProductSamples.DockingSamples.Demo.SimpleIde.SubWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="SubWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Grid>
<Button Click="Button_Click" Content="Active" />
</Grid>
</Window>
SubWindow.xaml.cs (Create new)
using System;
using System.Windows;
namespace ActiproSoftware.ProductSamples.DockingSamples.Demo.SimpleIde
{
/// <summary>
/// SubWindow.xaml の相互作用ロジック
/// </summary>
public partial class SubWindow : Window
{
public Action ActiveAction { get; set; }
public SubWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ActiveAction?.Invoke();
}
}
}
MainControl.xaml(2)
- Add menu item to show SubWindow.
<Menu>
<MenuItem Header="_File">
<MenuItem Click="OnSubWindowMenuClick" Header="Sub Window" />
MainControl.xaml.cs
- Add event handler
private void OnSubWindowMenuClick(object sender, RoutedEventArgs e)
{
var w = new SubWindow();
w.ActiveAction = () => WebView2ToolWindow.IsActive = true;
w.ShowDialog();
}