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

Support Right-to-Left layout for PopupMenu and SecondWindow #152

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public partial class TaskbarIcon
[SupportedOSPlatform("windows5.1.2600")]
private void ShowContextMenuInPopupMenuMode(System.Drawing.Point cursorPosition)
{
var menu = new H.NotifyIcon.Core.PopupMenu();
var menu = new H.NotifyIcon.Core.PopupMenu
{
RightToLeft = FlowDirection == FlowDirection.RightToLeft
};
#if HAS_MAUI
PopulateMenu(menu.Items, (MenuFlyout)ContextFlyout);
#else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using H.NotifyIcon.Interop;
using Microsoft.UI.Xaml.Data;

namespace H.NotifyIcon;

Expand Down Expand Up @@ -60,6 +61,15 @@ private void PrepareContextMenuWindow()
{
Background = new SolidColorBrush(Colors.Transparent),
};

var flowDirectionBinding = new Binding
{
Source = this,
Path = new PropertyPath(nameof(FlowDirection)),
Mode = BindingMode.OneWay,
};
BindingOperations.SetBinding(frame, FlowDirectionProperty, flowDirectionBinding);

var window = new Window()
{
Content = frame,
Expand Down
10 changes: 10 additions & 0 deletions src/libs/H.NotifyIcon/PopupMenus/PopupMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class PopupMenu
/// </summary>
public ICollection<PopupItem> Items { get; } = new List<PopupItem>();

/// <summary>
///
/// </summary>
public bool RightToLeft { get; set; }

/// <summary>
///
/// </summary>
Expand All @@ -30,6 +35,11 @@ public void Show(nint ownerHandle, int x, int y)
TRACK_POPUP_MENU_FLAGS.TPM_NONOTIFY |
TRACK_POPUP_MENU_FLAGS.TPM_BOTTOMALIGN;

if (RightToLeft)
{
flags |= TRACK_POPUP_MENU_FLAGS.TPM_LAYOUTRTL;
}

BOOL id;

var lastId = 1;
Expand Down
Loading