mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
deferload experiment
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.Behaviors;
|
||||
using Microsoft.UI.Xaml;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Snap.Hutao.Control.Behavior;
|
||||
|
||||
[DependencyProperty("ElementNames", typeof(DeferLoadCollection))]
|
||||
internal sealed partial class DeferLoadBehavior : BehaviorBase<FrameworkElement>
|
||||
{
|
||||
protected override bool Initialize()
|
||||
{
|
||||
if (ElementNames.IsNullOrEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ThreadPool.UnsafeQueueUserWorkItem(LoadElements, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void LoadElements(object? state)
|
||||
{
|
||||
if (state is not DeferLoadBehavior behavior)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<string>? elementNames = null;
|
||||
behavior.AssociatedObject.DispatcherQueue.Invoke(() => elementNames = [.. behavior.ElementNames]);
|
||||
|
||||
foreach (string name in CollectionsMarshal.AsSpan(elementNames))
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
|
||||
behavior.AssociatedObject.DispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
behavior.AssociatedObject.FindName(name);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Windows.Foundation.Metadata;
|
||||
|
||||
namespace Snap.Hutao.Control.Behavior;
|
||||
|
||||
[CreateFromString(MethodName = "Snap.Hutao.Control.Behavior.DeferLoadCollection.Parse")]
|
||||
internal sealed class DeferLoadCollection : List<string>
|
||||
{
|
||||
public static DeferLoadCollection Parse(string text)
|
||||
{
|
||||
DeferLoadCollection collection = [];
|
||||
foreach (StringSegment segment in new StringTokenizer(text, [',']))
|
||||
{
|
||||
if (segment.HasValue)
|
||||
{
|
||||
collection.Add(segment.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
15
src/Snap.Hutao/Snap.Hutao/View/Helper/LoadDeferral.cs
Normal file
15
src/Snap.Hutao/Snap.Hutao/View/Helper/LoadDeferral.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Windows.Foundation.Metadata;
|
||||
|
||||
namespace Snap.Hutao.View.Helper;
|
||||
|
||||
internal sealed class LoadDeferral : ObservableObject
|
||||
{
|
||||
private bool canLoad;
|
||||
|
||||
public bool CanLoad { get => canLoad; set => SetProperty(ref canLoad, value); }
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
<shvcs:BackdropTypeToOpacityConverter x:Key="BackdropTypeToOpacityConverter"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid Transitions="{ThemeResource EntranceThemeTransitions}">
|
||||
<Grid>
|
||||
<Border Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" Opacity="{Binding AppOptions.BackdropType, Converter={StaticResource BackdropTypeToOpacityConverter}, Mode=OneWay}">
|
||||
<Border.OpacityTransition>
|
||||
<ScalarTransition Duration="0:0:1"/>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
mc:Ignorable="d">
|
||||
<mxi:Interaction.Behaviors>
|
||||
<shcb:InvokeCommandOnLoadedBehavior Command="{Binding OpenUICommand}"/>
|
||||
<shcb:DeferLoadBehavior ElementNames="TopPanel,GameAnnouncementPivot"/>
|
||||
</mxi:Interaction.Behaviors>
|
||||
<shc:ScopedPage.Resources>
|
||||
<shc:BindingProxy x:Key="BindingProxy" DataContext="{Binding}"/>
|
||||
@@ -207,7 +208,7 @@
|
||||
<Grid>
|
||||
<ScrollViewer Padding="0" Style="{StaticResource DefaultScrollViewerStyle}">
|
||||
<StackPanel>
|
||||
<StackPanel>
|
||||
<StackPanel Name="TopPanel">
|
||||
<TextBlock
|
||||
Margin="16,16,16,0"
|
||||
Style="{StaticResource TitleTextBlockStyle}"
|
||||
@@ -240,7 +241,11 @@
|
||||
</ScrollViewer>
|
||||
</StackPanel>
|
||||
|
||||
<Pivot Style="{StaticResource DefaultPivotStyle}">
|
||||
<Pivot
|
||||
x:Name="GameAnnouncementPivot"
|
||||
x:Load="False"
|
||||
Style="{StaticResource DefaultPivotStyle}"
|
||||
Transitions="{ThemeResource EntranceThemeTransitions}">
|
||||
<PivotItem
|
||||
Content="{Binding Announcement.List[0]}"
|
||||
ContentTemplate="{StaticResource AnnouncementPivotItemContentTemplate}"
|
||||
|
||||
Reference in New Issue
Block a user