Skip to content

TooltipText binding missing in NotifyIcon #1426

@wingsweiwei

Description

@wingsweiwei

Describe the bug

The TooltipText binding in NotifyIcon is missing. The line 388 notifyIcon.TooltipText = e.NewValue as string ?? string.Empty; in Wpf.Ui.Tray.Controls.NotifyIcon is no need.

    private static void OnTooltipTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is not NotifyIcon notifyIcon)
        {
            return;
        }

        notifyIcon.TooltipText = e.NewValue as string ?? string.Empty;
        notifyIcon.internalNotifyIconManager.TooltipText = notifyIcon.TooltipText;
        _ = notifyIcon.internalNotifyIconManager.ModifyToolTip();
    }

To Reproduce

After startup the window. Check the Real-time visualization tree and Real-time property Explorer. The BindingExpress in TooltipText is missing.

There is my code :

...
        [ObservableProperty]
        private IStringLocalizer<Translations> _localizer;

        [RelayCommand]
        private void Test()
        {
            var cultureInfo = CultureInfo.GetCultureInfo("en-US");
            CultureInfo.CurrentCulture = cultureInfo;
            CultureInfo.CurrentUICulture = cultureInfo;
            OnPropertyChanged(nameof(Localizer));
        }
    <ui:FluentWindow.Resources>
        <ResourceDictionary>
            <controls:BindingProxy x:Key="proxy" Data="{Binding}"/>
        </ResourceDictionary>
    </ui:FluentWindow.Resources>
...
        <tray:NotifyIcon x:Name="NotifyIcon"
            Grid.Row="0"
            FocusOnLeftClick="True"
            Icon="pack://application:,,,/Assets/wpfui-icon-256.png"
            MenuOnRightClick="True"
            TooltipText="{Binding Localizer[ApplicationTitle]}">
            <tray:NotifyIcon.Menu>
                <ContextMenu DataContext="{Binding Data, Source={StaticResource proxy}}">
                    <MenuItem Header="{Binding Localizer[Test]}" Command="{Binding TestCommand}"/>
                    <Separator/>
                    <MenuItem Header="{Binding Localizer[Exit]}" Command="{Binding ExitCommand}"/>
                </ContextMenu>
            </tray:NotifyIcon.Menu>
        </tray:NotifyIcon>

Expected behavior

The TooltipText should be with a BindingExpress

Screenshots

Now Should be
Image Image

OS version

Windows 11

.NET version

net8.0-windows

WPF-UI NuGet version

<PackageReference Include="WPF-UI.Tray" Version="4.0.2" />

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions