I'm using NotifyIcon to implement a "minimize icon to tray" feature in my WPF app. The minimize works just fine, however if I click "open", the icon will re-appear on the taskbar but the app doesn't re-appear. I'm setting the TopMost
property to true
(I've tried the two solutions below) but still no luck. Very new to desktop apps so any direction/theories much appreciated.
Code Behind
private void TrayIconShowWindow_Click(object sender, RoutedEventArgs e)
{
WindowState = System.Windows.WindowState.Normal;
Visibility = Visibility.Visible;
// Neither of these work
Application.Current.MainWindow.Topmost = true;
Topmost = true;
}
XAML
<taskbar:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Open Window" Click="TrayIconShowWindow_Click">
<MenuItem.Icon>
<Image Width="16" Height="16" Source="Assets/OpenScreen.png"/>
</MenuItem.Icon>
</MenuItem>
<Separator/>
<MenuItem Header="Exit" Click="TrayIconExitApp_Click">
<MenuItem.Icon>
<Image Width="16" Height="16" Source="Assets/Close.png"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</taskbar:TaskbarIcon.ContextMenu>