我正在將一個 Electron 應用程式遷移到 WPF Webview2。
在我的 Electron 應用程式中,我有無框視窗。創建一個自定義的、可拖動的標題欄相當于在div我想要拖動的物件上添加一個 CSS 屬性:-webkit-app-region: drag
下面的例子:
主要.js:
const {app, BrowserWindow} = require('electron')
function createWindow () {
const mainWindow = new BrowserWindow()
mainWindow.loadFile('index.html')
mainWindow.webContents.setWindowOpenHandler(_ => {
return {
action: "allow",
overrideBrowserWindowOptions: {
frame: false
}
}
})
}
app.whenReady().then(() => {
createWindow()
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
索引.html:
<button onclick="window.open('index2.html')">Open Frameless Window</button>
index2.html:
<div style="-webkit-app-region: drag; background-color:green">Toolbar</div>
<div>Body</div>
在我的 Webview2 應用程式中,我有:
public static async void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
{
var obj = e.GetDeferral();
var win = new Window();
win.WindowStyle = WindowStyle.None; // remove the border
win.Show();
var w = new WebView2();
win.Content = w;
await w.EnsureCoreWebView2Async(MainWindow.Webview.CoreWebView2.Environment);
e.NewWindow = w.CoreWebView2;
obj.Complete();
}
視窗正確顯示而沒有邊框,但自定義標題欄不可拖動。似乎沒有看到 CSS 樣式或其他東西。
我怎樣才能讓這些樣式產生效果?
uj5u.com熱心網友回復:
WebView2 不支持該webkit-app-region: drag樣式。您需要按照此GitHub 問題 中的說明手動實作可拖動區域。
如果您愿意,可以在我們的 WebView2Feedback 專案上打開功能請求。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/330491.html
上一篇:檢測超出控制的點擊
