m.t.bennett
m.t.bennett

Reputation: 1320

WPF NotifyIcon - Hide Tray Popup

I'm currently using the (awesome) third party WPF NotifyIcon

I've created a Tray Popup like so:

    <tb:TaskbarIcon Name="tbIcon" IconSource="/Images/Icon.ico" PopupActivation="LeftOrRightClick" TrayMouseDoubleClick="tbIcon_TrayMouseDoubleClick">
        <tb:TaskbarIcon.TrayPopup>
            <Border Background="White" BorderBrush="Gray" BorderThickness="1" CornerRadius="3" Width="auto" Height="auto">
                    <DockPanel VerticalAlignment="Top" HorizontalAlignment="Right">
                        <Button DockPanel.Dock="Left" Name="btnSetupTray" Content="Setup" Margin="5" Width="70" Click="btnSetupTray_Click"></Button>
                        <Button DockPanel.Dock="Left" Name="btnExitTray" Content="Exit" Margin="5" Width="50" Click="btnExit_Click"></Button>
                    </DockPanel>
            </Border>
        </tb:TaskbarIcon.TrayPopup>
    </tb:TaskbarIcon>

I'm wondering how I can hide the tray popup programatically.

I've tried setting the tray popup visibility:

 tbIcon.TrayPopup.Visibility = Visibility.Collapsed;

which doesn't actually draw focus from the popup, meaning I have to double click another window to action something (like a button). It also means I have to set the visibility to Visible after focus has been drawn away from the popup.

Any help would be greatly appreciated!

Upvotes: 1

Views: 1956

Answers (2)

rahebirizah
rahebirizah

Reputation: 115

try

tbIcon.TrayPopupResolved.IsOpen = false;

Upvotes: 4

Dzoukr
Dzoukr

Reputation: 1145

Try to use IsOpen instead of Visibility property. It is weird, but is has setter which actually closes the popup.

tbIcon.TrayPopup.IsOpen = false;

Hope it helps.

Upvotes: 1

Related Questions