HavenDV / H.NotifyIcon

TrayIcon for WPF/WinUI/Uno/MAUI
MIT License
568 stars 46 forks source link

[WinUI] Menu items changes in c# code doesn't change contextmenu with SecondWindow mode #97

Open Jeric-X opened 1 year ago

Jeric-X commented 1 year ago

Describe the bug

MenuFlyoutName.Items.Add(new MenuFlyoutItem() { Text = "new added" });

changing MenuFlyou.Items doesn't change context menu If set ContextMenuMode=PopupMenu or ActiveWindow, context menu does change.

Steps to reproduce the bug

change H.NotifyIcon.Apps.WinUI project TrayIconView.xaml

    <tb:TaskbarIcon
        x:Name="TrayIcon"
        x:FieldModifier="public"
        IconSource="ms-appx:///Assets/Red.ico"
        ToolTipText="ToolTip"
        LeftClickCommand="{x:Bind ShowHideWindowCommand}"
        NoLeftClickDelay="True"
        ContextMenuMode="SecondWindow"
        >
        <tb:TaskbarIcon.ContextFlyout>

<!--  Changes here  -->
            <MenuFlyout AreOpenCloseAnimationsEnabled="False" x:Name="Menu">
                <MenuFlyoutItem Command="{x:Bind AddCommand}" Text="Add Item" />
<!--  Changes here  -->

                 <MenuFlyoutItem Command="{x:Bind ShowHideWindowCommand}" Text="Show/Hide Window" />
                <MenuFlyoutSeparator />
                <MenuFlyoutItem Command="{x:Bind ExitApplicationCommand}" Text="Exit" />
            </MenuFlyout>
        </tb:TaskbarIcon.ContextFlyout>
    </tb:TaskbarIcon>

TrayIconView.xaml.cs

    [RelayCommand]
    public void Add()
    {
        Menu.Items.Add(new MenuFlyoutItem() { Text = "new added" });
    }

yeycuq1l ebw Then click "Add Item"

Expected behavior

Like PopupMenu mode, A new Item was Added vrjuvui4 y5p

Screenshots

No response

NuGet package version

2.0.108

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 11

WindowsAppSDK Version

Other

WindowsAppSDK Type

Packaged

Manifest

No response

Additional context

No response

Jeric-X commented 1 year ago

The reason is that the real working MenuFlyout(and it's Items) is the second transparent window's property. Items in xaml is just for preparation.