mirror of
https://github.com/scratchfoundation/scratch-link.git
synced 2025-06-11 12:50:39 -04:00
Merge pull request #44 from cwillisf/fix-windows-context-menu-sizing
fix(Win): fix sizing problem in context menu
This commit is contained in:
commit
2d0591e94b
2 changed files with 28 additions and 10 deletions
scratch-link-win
|
@ -6,12 +6,14 @@ namespace ScratchLink.Win;
|
|||
|
||||
using H.NotifyIcon;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using ScratchLink;
|
||||
using ScratchLink.Win.BLE;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using Windows.ApplicationModel.DataTransfer;
|
||||
using Windows.Foundation;
|
||||
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
|
@ -70,6 +72,23 @@ public partial class App : Application
|
|||
copyVersionCommand.Label = $"{this.appTitle} {this.versionQuad}";
|
||||
copyVersionCommand.ExecuteRequested += this.CopyVersionCommand_ExecuteRequested;
|
||||
|
||||
// Without this code, the width gets set too small and the label gets cut off.
|
||||
// This could be a different presentation of https://github.com/HavenDV/H.NotifyIcon/issues/73
|
||||
// Note that the "loop" should handle exactly one item due to the `Where` clause.
|
||||
var menuFlyout = (MenuFlyout)this.Resources["ContextFlyout"];
|
||||
foreach (var menuItem in menuFlyout.Items.OfType<MenuFlyoutItem>()
|
||||
.Where(item => (XamlUICommand)item.Command == copyVersionCommand))
|
||||
{
|
||||
var infiniteSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
|
||||
menuItem.Icon.Measure(infiniteSize);
|
||||
menuItem.Measure(infiniteSize);
|
||||
menuItem.Width =
|
||||
menuItem.Icon.Margin.Left + menuItem.Icon.DesiredSize.Width + menuItem.Icon.Margin.Right +
|
||||
menuItem.Margin.Left + menuItem.Padding.Left +
|
||||
menuItem.DesiredSize.Width +
|
||||
menuItem.Padding.Right + menuItem.Margin.Right;
|
||||
}
|
||||
|
||||
var exitCommand = (XamlUICommand)this.Resources["ExitCommand"];
|
||||
exitCommand.ExecuteRequested += this.ExitCommand_ExecuteRequested;
|
||||
|
||||
|
|
|
@ -12,19 +12,18 @@
|
|||
ToolTipText="Scratch Link"
|
||||
ContextMenuMode="SecondWindow"
|
||||
IconSource="scratch-link-tray.ico"
|
||||
>
|
||||
<tb:TaskbarIcon.ContextFlyout>
|
||||
<MenuFlyout>
|
||||
<MenuFlyoutItem Command="{StaticResource CopyVersionCommand}" />
|
||||
<MenuFlyoutSeparator />
|
||||
<MenuFlyoutItem Command="{StaticResource ExitCommand}" />
|
||||
</MenuFlyout>
|
||||
</tb:TaskbarIcon.ContextFlyout>
|
||||
</tb:TaskbarIcon>
|
||||
tb:TaskbarIcon.ContextFlyout="{StaticResource ContextFlyout}"
|
||||
/>
|
||||
|
||||
<MenuFlyout x:Key="ContextFlyout">
|
||||
<MenuFlyoutItem Command="{StaticResource CopyVersionCommand}" />
|
||||
<MenuFlyoutSeparator />
|
||||
<MenuFlyoutItem Command="{StaticResource ExitCommand}" />
|
||||
</MenuFlyout>
|
||||
|
||||
<XamlUICommand
|
||||
x:Key="CopyVersionCommand"
|
||||
Label="Scratch Link"
|
||||
Label="Scratch Link 2.0.0.0"
|
||||
Description="Copy version to clipboard"
|
||||
>
|
||||
<XamlUICommand.IconSource>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue