Skip to content

Commit ee85615

Browse files
fix context menu show problem
1 parent 6af8a1c commit ee85615

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ElectronNET-API-Demos/Controllers/MenusController.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ private void CreateContextMenu()
112112
new MenuItem { Label = "Electron.NET", Type = MenuType.checkbox, Checked = true }
113113
};
114114

115-
var mainWindow = Electron.WindowManager.BrowserWindows.FirstOrDefault();
116-
if (mainWindow == null) return;
117-
118-
Electron.Menu.SetContextMenu(mainWindow, menu);
115+
Electron.App.BrowserWindowFocus += () => {
116+
var mainWindow = Electron.WindowManager.BrowserWindows.FirstOrDefault();
117+
Electron.Menu.SetContextMenu(mainWindow, menu);
118+
};
119119

120120
Electron.IpcMain.On("show-context-menu", (args) =>
121121
{
122+
var mainWindow = Electron.WindowManager.BrowserWindows.FirstOrDefault();
122123
Electron.Menu.ContextMenuPopup(mainWindow);
123124
});
124125
}

0 commit comments

Comments
 (0)