mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
fix.修复了快捷方式组件无法正常透明的问题。
This commit is contained in:
@@ -8,9 +8,6 @@
|
||||
x:Class="LanMountainDesktop.Views.Components.ShortcutWidget">
|
||||
|
||||
<Border x:Name="RootBorder"
|
||||
Background="{DynamicResource AdaptiveSurfaceRaisedBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveButtonBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusComponent}"
|
||||
ClipToBounds="True">
|
||||
<Grid RowDefinitions="*,Auto"
|
||||
|
||||
@@ -25,6 +25,7 @@ public partial class ShortcutWidget : UserControl, IDesktopComponentWidget, ICom
|
||||
private bool _showBackground = true;
|
||||
private double _currentCellSize = 48;
|
||||
private bool _isDisposed;
|
||||
private bool _chromeApplied;
|
||||
|
||||
private const double TapMovementThreshold = 10;
|
||||
private const long TapTimeThresholdMs = 500;
|
||||
@@ -40,9 +41,32 @@ public partial class ShortcutWidget : UserControl, IDesktopComponentWidget, ICom
|
||||
{
|
||||
InitializeComponent();
|
||||
DoubleTapped += OnDoubleTapped;
|
||||
Loaded += OnLoaded;
|
||||
UpdateDisplay();
|
||||
}
|
||||
|
||||
private void OnLoaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// ApplyChrome() may have been called before the control was attached to the visual tree,
|
||||
// causing FindResource() to fail. Re-apply now that resources are available.
|
||||
if (!_chromeApplied)
|
||||
{
|
||||
ApplyChrome();
|
||||
}
|
||||
|
||||
// Subscribe to theme changes so the background follows theme updates.
|
||||
var themeService = HostAppearanceThemeProvider.GetOrCreate();
|
||||
themeService.Changed += OnAppearanceThemeChanged;
|
||||
}
|
||||
|
||||
private void OnAppearanceThemeChanged(object? sender, AppearanceThemeSnapshot e)
|
||||
{
|
||||
if (_isDisposed || _showBackground)
|
||||
{
|
||||
ApplyChrome();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetComponentPlacementContext(string componentId, string? placementId)
|
||||
{
|
||||
_componentId = string.IsNullOrWhiteSpace(componentId)
|
||||
@@ -258,13 +282,25 @@ public partial class ShortcutWidget : UserControl, IDesktopComponentWidget, ICom
|
||||
RootBorder.Background = Brushes.Transparent;
|
||||
RootBorder.BorderBrush = Brushes.Transparent;
|
||||
RootBorder.BorderThickness = new Thickness(0);
|
||||
_chromeApplied = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 恢复默认的实心背景样式
|
||||
RootBorder.Background = this.FindResource("AdaptiveSurfaceRaisedBrush") as IBrush ?? Brushes.Transparent;
|
||||
RootBorder.BorderBrush = this.FindResource("AdaptiveButtonBorderBrush") as IBrush ?? Brushes.Transparent;
|
||||
// FindResource requires the control to be attached to the visual tree.
|
||||
// If it returns null, _chromeApplied stays false so OnLoaded will retry.
|
||||
var background = this.FindResource("AdaptiveSurfaceRaisedBrush") as IBrush;
|
||||
var borderBrush = this.FindResource("AdaptiveButtonBorderBrush") as IBrush;
|
||||
|
||||
if (background is null || borderBrush is null)
|
||||
{
|
||||
_chromeApplied = false;
|
||||
return;
|
||||
}
|
||||
|
||||
RootBorder.Background = background;
|
||||
RootBorder.BorderBrush = borderBrush;
|
||||
RootBorder.BorderThickness = new Thickness(1);
|
||||
_chromeApplied = true;
|
||||
}
|
||||
|
||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||
@@ -391,6 +427,10 @@ public partial class ShortcutWidget : UserControl, IDesktopComponentWidget, ICom
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
var themeService = HostAppearanceThemeProvider.GetOrCreate();
|
||||
themeService.Changed -= OnAppearanceThemeChanged;
|
||||
|
||||
_gestureStates.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user