using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
namespace Avalonia.Xaml.Interactions.Custom;
///
///
///
public abstract class ShowBehaviorBase : AttachedToVisualTreeBehavior
{
///
/// Identifies the avalonia property.
///
public static readonly StyledProperty TargetControlProperty =
AvaloniaProperty.Register(nameof(TargetControl));
///
///
///
public static readonly StyledProperty EventRoutingStrategyProperty =
AvaloniaProperty.Register(nameof(EventRoutingStrategy), RoutingStrategies.Bubble);
///
/// Gets or sets the target control. This is a avalonia property.
///
[ResolveByName]
public Control? TargetControl
{
get => GetValue(TargetControlProperty);
set => SetValue(TargetControlProperty, value);
}
///
///
///
public RoutingStrategies EventRoutingStrategy
{
get => GetValue(EventRoutingStrategyProperty);
set => SetValue(EventRoutingStrategyProperty, value);
}
///
///
///
///
protected bool Show()
{
if (IsEnabled && TargetControl is { IsVisible: false })
{
TargetControl.SetCurrentValue(Visual.IsVisibleProperty, true);
Dispatcher.UIThread.Post(() => TargetControl.Focus());
return true;
}
return false;
}
}