我有標準的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