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:

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

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);
}
}
I know, I'm being archeologist here, but hey, question has not been answered!
Tested on my setup, which is Windows 10 build 19045.3570, with WPF App both in .NET Framework 4.8 and .NET6 with Hardcodet.NotifyIcon.Wpf v.1.1.0 installed.
The problem is no longer there, in my case in both, calling the
TaskBatItemcreated inApp.xamlor inMainWindow.xaml,FancyBalloonwas being showed correctly.And btw in question there's
FancyBalloon UserControlimplementation missing (not my code, taken from https://www.codeproject.com/Articles/36468/WPF-NotifyIcon-2).UI
CodeBehind