review requests

This commit is contained in:
qhy040404
2024-06-13 15:36:50 +08:00
parent cc71aa9c82
commit 7a8c233b10
3 changed files with 60 additions and 17 deletions

View File

@@ -12,18 +12,18 @@ internal sealed partial class InfoBarDelayCloseBehavior : BehaviorBase<InfoBar>
{ {
protected override void OnAssociatedObjectLoaded() protected override void OnAssociatedObjectLoaded()
{ {
DelayCoreAsync().SafeForget(); if (MilliSecondsDelay > 0)
{
DelayCoreAsync().SafeForget();
}
} }
private async ValueTask DelayCoreAsync() private async ValueTask DelayCoreAsync()
{ {
if (MilliSecondsDelay > 0) await Delay.FromMilliSeconds(MilliSecondsDelay).ConfigureAwait(true);
if (AssociatedObject is not null)
{ {
await Delay.FromMilliSeconds(MilliSecondsDelay).ConfigureAwait(true); AssociatedObject.IsOpen = false;
if (AssociatedObject is not null)
{
AssociatedObject.IsOpen = false;
}
} }
} }
} }

View File

@@ -0,0 +1,25 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Service.Notification;
namespace Snap.Hutao.Control.Selector;
internal sealed class InfoBarTemplateSelector : DataTemplateSelector
{
public DataTemplate ActionButtonEnabled { get; set; } = default!;
public DataTemplate ActionButtonDisabled { get; set; } = default!;
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
if (item is InfoBarOptions { ActionButtonContent: { }, ActionButtonCommand: { } })
{
return ActionButtonEnabled;
}
return ActionButtonDisabled;
}
}

View File

@@ -8,6 +8,7 @@
xmlns:mxi="using:Microsoft.Xaml.Interactivity" xmlns:mxi="using:Microsoft.Xaml.Interactivity"
xmlns:shcb="using:Snap.Hutao.Control.Behavior" xmlns:shcb="using:Snap.Hutao.Control.Behavior"
xmlns:shcm="using:Snap.Hutao.Control.Markup" xmlns:shcm="using:Snap.Hutao.Control.Markup"
xmlns:shcs="using:Snap.Hutao.Control.Selector"
xmlns:shsn="using:Snap.Hutao.Service.Notification" xmlns:shsn="using:Snap.Hutao.Service.Notification"
mc:Ignorable="d"> mc:Ignorable="d">
@@ -63,25 +64,38 @@
<DataTemplate x:Key="InfoBarTemplate" x:DataType="shsn:InfoBarOptions"> <DataTemplate x:Key="InfoBarTemplate" x:DataType="shsn:InfoBarOptions">
<InfoBar <InfoBar
Title="{Binding Title}" Title="{Binding Title}"
Closed="OnInfoBarClosed"
Content="{Binding Content}"
IsOpen="True"
Message="{Binding Message}"
Severity="{Binding Severity}">
<mxi:Interaction.Behaviors>
<shcb:InfoBarDelayCloseBehavior MilliSecondsDelay="{Binding MilliSecondsDelay}"/>
</mxi:Interaction.Behaviors>
</InfoBar>
</DataTemplate>
<DataTemplate x:Key="InfoBarWithActionButtonTemplate" x:DataType="shsn:InfoBarOptions">
<InfoBar
Title="{Binding Title}"
Closed="OnInfoBarClosed"
Content="{Binding Content}" Content="{Binding Content}"
IsOpen="True" IsOpen="True"
Message="{Binding Message}" Message="{Binding Message}"
Closed="OnInfoBarClosed"
Severity="{Binding Severity}"> Severity="{Binding Severity}">
<InfoBar.Transitions>
<AddDeleteThemeTransition/>
</InfoBar.Transitions>
<InfoBar.ActionButton> <InfoBar.ActionButton>
<Button <Button Command="{Binding ActionButtonCommand}" Content="{Binding ActionButtonContent}"/>
Command="{Binding ActionButtonCommand}"
Content="{Binding ActionButtonContent}"
Visibility="{Binding ActionButtonContent, Converter={StaticResource EmptyObjectToVisibilityConverter}}"/>
</InfoBar.ActionButton> </InfoBar.ActionButton>
<mxi:Interaction.Behaviors> <mxi:Interaction.Behaviors>
<shcb:InfoBarDelayCloseBehavior MilliSecondsDelay="{Binding MilliSecondsDelay}"/> <shcb:InfoBarDelayCloseBehavior MilliSecondsDelay="{Binding MilliSecondsDelay}"/>
</mxi:Interaction.Behaviors> </mxi:Interaction.Behaviors>
</InfoBar> </InfoBar>
</DataTemplate> </DataTemplate>
<shcs:InfoBarTemplateSelector
x:Key="InfoBarTemplateSelector"
ActionButtonDisabled="{StaticResource InfoBarTemplate}"
ActionButtonEnabled="{StaticResource InfoBarWithActionButtonTemplate}"/>
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
@@ -91,9 +105,13 @@
Margin="32,48,32,32" Margin="32,48,32,32"
VerticalAlignment="Bottom" VerticalAlignment="Bottom"
ItemContainerTransitions="{StaticResource RepositionThemeTransitions}" ItemContainerTransitions="{StaticResource RepositionThemeTransitions}"
ItemTemplate="{StaticResource InfoBarTemplate}" ItemTemplateSelector="{StaticResource InfoBarTemplateSelector}"
ItemsSource="{x:Bind InfoBars}" ItemsSource="{x:Bind InfoBars}"
Visibility="{x:Bind VisibilityButton.IsChecked, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}"/> Visibility="{x:Bind VisibilityButton.IsChecked, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
<ItemsControl.Transitions>
<AddDeleteThemeTransition/>
</ItemsControl.Transitions>
</ItemsControl>
<Border <Border
Margin="16" Margin="16"