Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] NotifyIcon 支持无窗口时运行 #748

Closed
GiantappMan opened this issue Mar 26, 2021 · 4 comments
Closed

[Feature request] NotifyIcon 支持无窗口时运行 #748

GiantappMan opened this issue Mar 26, 2021 · 4 comments
Labels
🐛 bug Something isn't working

Comments

@GiantappMan
Copy link

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.

@NaBian NaBian closed this as completed in ad32fc8 Mar 28, 2021
@GiantappMan
Copy link
Author

能更新一个nuget版本么,感谢

@ghost1372 ghost1372 added the 🐛 bug Something isn't working label Apr 1, 2021
@GF-Huang
Copy link
Member

GF-Huang commented May 7, 2021

Same issue. Is it fixed and release to NuGet?

@NaBian
Copy link
Member

NaBian commented May 8, 2021

@GF-Huang
Copy link
Member

GF-Huang commented May 8, 2021

有无可能直接在 app.xaml 中定义 NotifyIcon 而不用手写 C# 代码去定义?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants