I use Hardcodet WPF NotifyIcon to display custom balloons on any event.
If I create TaskbarIconMainWindow in xaml, then my balloon is placed next to the taskbar:

But when I create TaskbarIconin the resource file (xaml) or application class, my ball is placed above the taskbar:

Why is there a difference in behavior between these cases and how to control the position of custom balloons?
EDIT : I use the following code to verify 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();
((App)Application.Current).AppTrayIcon.ShowCustomBalloon(bal, PopupAnimation.Slide, null);
}
}
source
share