Skip to content

Commit

Permalink
feat: Support Right-to-Left layout for PopupMenu and SecondWindow (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
Khiro95 authored Apr 26, 2024
1 parent b714a2e commit 8574be8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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

0 comments on commit 8574be8

Please sign in to comment.