Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to hide second window? (WinApp SDK) #144

Open
HavenDV opened this issue Mar 2, 2024 Discussed in #143 · 1 comment
Open

How to hide second window? (WinApp SDK) #144

HavenDV opened this issue Mar 2, 2024 Discussed in #143 · 1 comment

Comments

@HavenDV
Copy link
Owner

HavenDV commented Mar 2, 2024

Discussed in #143

Originally posted by TRadigk March 2, 2024
Hi,

consider following xaml for a window (from base Winui project):

<Window
    x:Class="H_Notify_WinUi.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:H_Notify_WinUi"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:notifyIcon="using:H.NotifyIcon"
    mc:Ignorable="d">
    <Grid>
        <notifyIcon:TaskbarIcon ToolTipText="Foo me ToolTip" ContextMenuMode="SecondWindow" NoLeftClickDelay="True"
                                x:Name="TrayIconFoo" >
            <notifyIcon:TaskbarIcon.IconSource>
                <notifyIcon:GeneratedIconSource
                    Text="❤️"
                    Foreground="Red" />
            </notifyIcon:TaskbarIcon.IconSource>
            <notifyIcon:TaskbarIcon.ContextFlyout>
                <MenuFlyout x:Name="Menu">
                    <MenuFlyoutItem Text="Test" Command="{x:Bind DoSomethingCommand}" />
                    <MenuFlyoutItem Text="Test" />
                    <MenuFlyoutItem Text="Test" />
                </MenuFlyout>

            </notifyIcon:TaskbarIcon.ContextFlyout>

        </notifyIcon:TaskbarIcon>

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
        </StackPanel>
    </Grid>
</Window>

with following code behind:

using System.Diagnostics;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls.Primitives;
using CommunityToolkit.Mvvm.Input;
using H.NotifyIcon.Core;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace H_Notify_WinUi
{
    /// <summary>
    /// An empty window that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
            TrayIconFoo.PopupActivation = PopupActivationMode.LeftClick;
            TrayIconFoo.ContextFlyout.ShowMode = FlyoutShowMode.Transient;
        }

        private void myButton_Click(object sender, RoutedEventArgs e)
        {
            myButton.Content = "Clicked";
        }

        [RelayCommand]
        private void DoSomething()
        {
            TrayIconFoo.ContextFlyout.Hide();
            TrayIconFoo.CloseTrayPopup();
            Menu.Hide();
            Debug.WriteLine("Fooooooooo");

        }
    }
}

How do I hide the opened menu when the task bar icon was clicked?

TrayIconCannotHideMenu

@HavenDV
Copy link
Owner Author

HavenDV commented Mar 2, 2024

Hi. Thank you for raising the issue. Since the development of this, a whole series of new versions of WindowsAppSdk have been released, and I think I need to fix this for the current version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant