Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create an application in WPF that runs in background

Tags:

c#

wpf

My aim is to place my application in the tray bar but I don't know how to do that for a WPF application ! (for a winform there is lots of docs but I don't find anything for Wpf)

Thanks

like image 811
Orpheo Avatar asked Oct 11 '22 14:10

Orpheo


1 Answers

You could use this library for the tray icon, and to not have any windows you should remove any StartupUri that may be defined in the App class by default. Then you can override OnStartup to prepare any logic that your application should perform.

Not sure if you can assign a TaskbarIcon of this library directly to the application since it is normally used on Windows. But you can create a dummy popup to make it show up.

public TaskbarIcon MyTaskbarIcon { get; set; }

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);
    Popup pu = new Popup();
    pu.Child = MyTaskbarIcon;
    //...
}

If you can have windows you can create a TaskbarIcon there and then you can call Hide() if you need it to completely disappear.

like image 171
H.B. Avatar answered Oct 14 '22 02:10

H.B.