我有标准的WPF应用程序使用ChromiumWebBrowser CefSharp.Wpf.dll 49.0.0.0。 版本升级到最新版本将是真正的噩梦,因此我不能认为它是一个选项。 我有一个小bug与开闭开发工具:WPF ChromiumWebBrowser打开和关闭开发工具的最佳方式
我通过命令来打开我的开发工具绑定:
<FrameworkElement.Resources>
<views:FreezableProxyClass x:Key="ProxyElement"
ProxiedDataContext="{Binding Source={x:Reference This}, Path=DataContext}" />
</FrameworkElement.Resources>
<FrameworkElement.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding OpenDevToolsCommand}"
Header="Open Chrome Dev Tools">
<MenuItem.Icon>
<Image Source="../../Images/dev_tools_20x20.png"
Width="20"
Height="20" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</FrameworkElement.ContextMenu>
<FrameworkElement.InputBindings>
<KeyBinding Key="F12"
Command="{Binding Source={StaticResource ProxyElement},
Path=ProxiedDataContext.OpenDevToolsCommand}" />
</FrameworkElement.InputBindings>
<browser:WebBrowserEx BrowserContainer="{Binding}" />
命令处理程序代码:
private void OpenDevToolsCommandHandler()
{
if (Browser.IsBrowserInitialized)
{
Browser.ForceShowingDevTools = !Browser.ForceShowingDevTools;
}
else
{
MessageBox.Show("Wait till the full browser initialization", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
和扩展的网络浏览器的代码有依赖属性:
public bool ForceShowingDevTools
{
get { return (bool)GetValue(ForceShowingDevToolsProperty); }
set { SetValue(ForceShowingDevToolsProperty, value); }
}
// Using a DependencyProperty as the backing store for ForceShowingDevTools. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ForceShowingDevToolsProperty =
DependencyProperty.Register("ForceShowingDevTools", typeof(bool), typeof(WebBrowserEx), new PropertyMetadata(false,
(o, e) =>
{
WebBrowserEx browserEx = o as WebBrowserEx;
if (browserEx != null)
{
if ((bool)e.NewValue)
{
browserEx.ShowDevTools();
}
else
{
browserEx.CloseDevTools();
}
}
}));
而ShowDevTools
和CloseDevTools
取自原始WebBrowserExtensions
类。
当我通过上下文菜单或F12键绑定打开和关闭我的开发工具时,它工作正常,但是当我通过开发工具窗口右上角的“关闭窗口”按钮关闭开发工具时,我的代码无法识别:
在下次命令调用该处理程序,我的应用程序认为浏览器中打开并试图将其关闭该关闭不通知我的财产,因此。因此我需要调用我的命令两次才能打开开发工具,如果它之前没有通过我的命令绑定关闭(从“X”按钮)。
是否有替代选项来打开和关闭开发工具?
'CefSharp'的最新版本是'57.0.0'。你能够使用'CefSharp.Wpf.Example'来复制这个吗?克隆https://github.com/cefsharp/CefSharp并给它一个测试。 :) – TEK
正如我上面写的,更新到最新版本将成为一场噩梦。 意思是,如果我有更新和保持这个错误之间的选择 - 我宁愿留在这个错误。 –
啊,道歉。我使用'master'分支('58.0.0')给它做了一个测试,因为我碰巧打开它,我无法复制它。猜测自从'49.0.0'以来它已经被修复了。我经常发现升级'CefSharp'是无痛的,但是我完全理解你的环境是不是这样。 – TEK