6

I use Hardcodet WPF NotifyIcon to show custom ballons on some event.

If I create TaskbarIcon in xaml of MainWindow, then my balloon is placed near taskbar:

TaskbarIcon created in MainWindow

But when I create TaskbarIcon in resource file (xaml) or an application class, then my balloon is placed over taskbar:

enter image description here

Why there is the difference in behaviour between these cases and how to control position of custom balloons?

EDIT: I use next code to test it:

(App.xaml):

<Application x:Class="TestBalloon.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:tb="http://www.hardcodet.net/taskbar"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <tb:TaskbarIcon x:Key="TrayIcon" ToolTipText="Created From Resources" />
    </Application.Resources>
</Application>

(App.xaml.cs):

public partial class App : Application
{
    public TaskbarIcon AppTrayIcon;

    protected override void OnStartup(StartupEventArgs e)
    {
        AppTrayIcon = (TaskbarIcon)FindResource("TrayIcon");
    }
}

(MainWindow.xaml):

<Window x:Class="TestBalloon.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tb="http://www.hardcodet.net/taskbar"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <tb:TaskbarIcon x:Name="MainWindowTrayIcon" ToolTipText="Created in MainWindow" />

        <Button x:Name="MyButton" 
                Content="ClickMe"
                Margin="10,10,10,10"
                Click="MyButton_OnClick"/>
    </Grid>
</Window>

(MainWindow.xaml.cs):

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void MyButton_OnClick(object sender, RoutedEventArgs e)
    {
        FancyBalloon bal = new FancyBalloon(); // From Hardcodet WPF NotifyIcon Tutorial

        // To use TaskbarItem created in MainWindow.xaml
        //MainWindowTrayIcon.ShowCustomBalloon(bal, PopupAnimation.Slide, null);

        // To use TaskbarItem created in App.xaml
        ((App)Application.Current).AppTrayIcon.ShowCustomBalloon(bal, PopupAnimation.Slide, null);
    }
}
Gendolph
  • 463
  • 7
  • 12
  • 1
    Post the XAML in both cases. – Federico Berasategui Jun 30 '14 at 14:17
  • *Why there is the difference in behaviour between these cases*... because *you* defined different code for them. Please show it. – Sheridan Jun 30 '14 at 14:19
  • There you go... you probably get a difference in appearance because you are using different code to launch them: `AppTrayIcon = (TaskbarIcon)FindResource("TrayIcon");` and `((App)Application.Current).AppTrayIcon.ShowCustomBalloon(bal, PopupAnimation.Slide, null);`. – Sheridan Jun 30 '14 at 14:47
  • @Sheridan: I do this only to get object (`TaskbarIcon`). `AppTrayIcon` is only name of reference on `TaskbarIcon` (created in App.xaml). Name of similar object (created in MainWindow.xaml) is `MainWindowTrayIcon`. What difference in running the code? – Gendolph Jun 30 '14 at 15:01
  • *Why there is the difference in behaviour between these cases*... as previously requested, please show the code *for both of your cases*. – Sheridan Jun 30 '14 at 15:10
  • @Sheridan, code presented already for both cases, see last code block in post. Call of method `ShowCustomBalloon` for first case is commented, because in such case I did not launch both cases simultaniusly. So, first launch is `MainWindowTrayIcon.ShowCustomBalloon(...)`, and second one is `((App)Application.Current).AppTrayIcon.ShowCustomBalloon(...)`. – Gendolph Jun 30 '14 at 19:51
  • Apologies, my eyes must just automatically ignore comments. Now that I see it, I think that you've presented a good question. +1 – Sheridan Jun 30 '14 at 20:39
  • Cannot reproduce the issue in Windows 8. Both popups display above the taskbar rather than beside of it. – Stefan Over Jul 01 '14 at 07:31
  • @Herdo, I try it on Win8. On one machine the behaviour was the same, but on another machine (also Win8) both balloons were near the taskbar. I'm confused. – Gendolph Jul 01 '14 at 13:37
  • Is there any solution for this problem? – thardes2 Mar 16 '16 at 11:22

0 Answers0