mirror of
https://github.com/microsoft/PowerToys
synced 2024-11-22 00:03:48 +00:00
[Peek]Update FilePreviewer to prevent tooltips from obscuring title bar controls (#34718)
* Update FilePreviewer to prevent tooltips from obscuring title bar controls. Fixes #34496 * Small tidy to pointer move handler and StringBuilder setup.
This commit is contained in:
parent
035d70dd04
commit
a70aafb3b8
@ -29,18 +29,25 @@
|
||||
x:Name="ImagePreview"
|
||||
MaxWidth="{x:Bind ImagePreviewer.MaxImageSize.Width, Mode=OneWay}"
|
||||
MaxHeight="{x:Bind ImagePreviewer.MaxImageSize.Height, Mode=OneWay}"
|
||||
PointerMoved="ToolTipParentControl_PointerMoved"
|
||||
Source="{x:Bind ImagePreviewer.Preview, Mode=OneWay}"
|
||||
ToolTipService.ToolTip="{x:Bind InfoTooltip, Mode=OneWay}"
|
||||
Visibility="{x:Bind IsPreviewVisible(ImagePreviewer, Previewer.State), Mode=OneWay}" />
|
||||
Visibility="{x:Bind IsPreviewVisible(ImagePreviewer, Previewer.State), Mode=OneWay}">
|
||||
<ToolTipService.ToolTip>
|
||||
<ToolTip Content="{x:Bind InfoTooltip, Mode=OneWay}" />
|
||||
</ToolTipService.ToolTip>
|
||||
</Image>
|
||||
|
||||
<MediaPlayerElement
|
||||
x:Name="VideoPreview"
|
||||
AreTransportControlsEnabled="True"
|
||||
AutoPlay="True"
|
||||
FlowDirection="LeftToRight"
|
||||
PointerMoved="ToolTipParentControl_PointerMoved"
|
||||
Source="{x:Bind VideoPreviewer.Preview, Mode=OneWay}"
|
||||
ToolTipService.ToolTip="{x:Bind InfoTooltip, Mode=OneWay}"
|
||||
Visibility="{x:Bind IsPreviewVisible(VideoPreviewer, Previewer.State), Mode=OneWay}">
|
||||
<ToolTipService.ToolTip>
|
||||
<ToolTip Content="{x:Bind InfoTooltip, Mode=OneWay}" />
|
||||
</ToolTipService.ToolTip>
|
||||
<MediaPlayerElement.KeyboardAccelerators>
|
||||
<KeyboardAccelerator Key="Space" Invoked="KeyboardAccelerator_Space_Invoked" />
|
||||
</MediaPlayerElement.KeyboardAccelerators>
|
||||
|
@ -13,6 +13,7 @@ using ManagedCommon;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Peek.Common.Extensions;
|
||||
@ -340,10 +341,8 @@ namespace Peek.FilePreviewer
|
||||
}
|
||||
|
||||
// Fetch and format available file properties
|
||||
var sb = new StringBuilder();
|
||||
|
||||
string fileNameFormatted = ReadableStringHelper.FormatResourceString("PreviewTooltip_FileName", Item.Name);
|
||||
sb.Append(fileNameFormatted);
|
||||
var sb = new StringBuilder(fileNameFormatted, 256);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
string fileType = await Task.Run(Item.GetContentTypeAsync);
|
||||
@ -360,5 +359,23 @@ namespace Peek.FilePreviewer
|
||||
|
||||
InfoTooltip = sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the placement of the tooltip for those previewers supporting the feature, ensuring it does not obscure the Main Window's title bar.
|
||||
/// </summary>
|
||||
private void ToolTipParentControl_PointerMoved(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
var previewControl = sender as FrameworkElement;
|
||||
if (previewControl != null)
|
||||
{
|
||||
var toolTip = ToolTipService.GetToolTip(previewControl) as ToolTip;
|
||||
if (toolTip != null)
|
||||
{
|
||||
var pos = e.GetCurrentPoint(previewControl).Position;
|
||||
toolTip.Placement = pos.Y < previewControl.ActualHeight / 2 ?
|
||||
PlacementMode.Bottom : PlacementMode.Top;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user