mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix #924
This commit is contained in:
@@ -14,12 +14,31 @@ namespace Snap.Hutao.Control.Behavior;
|
||||
[DependencyProperty("CommandParameter", typeof(object))]
|
||||
internal sealed partial class InvokeCommandOnLoadedBehavior : BehaviorBase<UIElement>
|
||||
{
|
||||
private bool executed;
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
|
||||
// FrameworkElement in a ItemsRepeater gets attached twice
|
||||
if (!executed && AssociatedObject is FrameworkElement { IsLoaded: true })
|
||||
{
|
||||
TryExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnAssociatedObjectLoaded()
|
||||
{
|
||||
TryExecuteCommand();
|
||||
}
|
||||
|
||||
private void TryExecuteCommand()
|
||||
{
|
||||
if (Command is not null && Command.CanExecute(CommandParameter))
|
||||
{
|
||||
Command.Execute(CommandParameter);
|
||||
executed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user