mirror of
https://github.com/scratchfoundation/scratch-link.git
synced 2025-06-27 22:30:27 -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 H.NotifyIcon;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Input;
|
using Microsoft.UI.Xaml.Input;
|
||||||
using ScratchLink;
|
using ScratchLink;
|
||||||
using ScratchLink.Win.BLE;
|
using ScratchLink.Win.BLE;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Windows.ApplicationModel.DataTransfer;
|
using Windows.ApplicationModel.DataTransfer;
|
||||||
|
using Windows.Foundation;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides application-specific behavior to supplement the default Application class.
|
/// 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.Label = $"{this.appTitle} {this.versionQuad}";
|
||||||
copyVersionCommand.ExecuteRequested += this.CopyVersionCommand_ExecuteRequested;
|
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"];
|
var exitCommand = (XamlUICommand)this.Resources["ExitCommand"];
|
||||||
exitCommand.ExecuteRequested += this.ExitCommand_ExecuteRequested;
|
exitCommand.ExecuteRequested += this.ExitCommand_ExecuteRequested;
|
||||||
|
|
||||||
|
|
|
@ -12,19 +12,18 @@
|
||||||
ToolTipText="Scratch Link"
|
ToolTipText="Scratch Link"
|
||||||
ContextMenuMode="SecondWindow"
|
ContextMenuMode="SecondWindow"
|
||||||
IconSource="scratch-link-tray.ico"
|
IconSource="scratch-link-tray.ico"
|
||||||
>
|
tb:TaskbarIcon.ContextFlyout="{StaticResource ContextFlyout}"
|
||||||
<tb:TaskbarIcon.ContextFlyout>
|
/>
|
||||||
<MenuFlyout>
|
|
||||||
<MenuFlyoutItem Command="{StaticResource CopyVersionCommand}" />
|
<MenuFlyout x:Key="ContextFlyout">
|
||||||
<MenuFlyoutSeparator />
|
<MenuFlyoutItem Command="{StaticResource CopyVersionCommand}" />
|
||||||
<MenuFlyoutItem Command="{StaticResource ExitCommand}" />
|
<MenuFlyoutSeparator />
|
||||||
</MenuFlyout>
|
<MenuFlyoutItem Command="{StaticResource ExitCommand}" />
|
||||||
</tb:TaskbarIcon.ContextFlyout>
|
</MenuFlyout>
|
||||||
</tb:TaskbarIcon>
|
|
||||||
|
|
||||||
<XamlUICommand
|
<XamlUICommand
|
||||||
x:Key="CopyVersionCommand"
|
x:Key="CopyVersionCommand"
|
||||||
Label="Scratch Link"
|
Label="Scratch Link 2.0.0.0"
|
||||||
Description="Copy version to clipboard"
|
Description="Copy version to clipboard"
|
||||||
>
|
>
|
||||||
<XamlUICommand.IconSource>
|
<XamlUICommand.IconSource>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue