-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
🐛 bugSomething isn't workingSomething isn't working
Description
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
App.xaml 不指定主窗口的情况下,直接启动托盘。目前实现不了。
Describe the solution you'd like
A clear and concise description of what you want to happen.
以下代码我测试了,可以显示icon,但是右键无法弹出contextMenu。
public partial class App : Application
{
NotifyIcon _notifyIcon = null;
protected override void OnStartup(StartupEventArgs e)
{
string apptEntryDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string iconPath = Path.Combine(apptEntryDir, "Assets\\Img\\logo.ico");
ContextMenu menu = new ContextMenu();
menu.Items.Add(new MenuItem() { Header = "主界面" });
menu.Items.Add(new MenuItem() { Header = "退出", Command = ControlCommands.ShutdownApp });
_notifyIcon = new NotifyIcon()
{
Token = "token",
Icon = new BitmapImage(new Uri(iconPath, UriKind.Absolute)),
ContextMenu = menu
};
_notifyIcon.Init();
base.OnStartup(e);
}
}
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
分析源码,我发现用IsLoaded过滤了事件处理。这句话屏蔽即可正常运行,不知道这样设计是否有什么特殊原因。
private IntPtr Callback(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
{
//if (IsLoaded)
Additional context
Add any other context or screenshots about the feature request here.
Metadata
Metadata
Assignees
Labels
🐛 bugSomething isn't workingSomething isn't working