Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Xaml.Interactivity;

namespace Avalonia.Xaml.Interactions.Custom;

/// <summary>
/// Sets the <see cref="Control.IsEnabled"/> property of a control when executed.

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 8 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved
/// </summary>
public class SetEnabledAction : StyledElementAction
{
/// <summary>
/// Identifies the <seealso cref="TargetControl"/> avalonia property.
/// </summary>
public static readonly StyledProperty<Control?> TargetControlProperty =
AvaloniaProperty.Register<SetEnabledAction, Control?>(nameof(TargetControl));

/// <summary>
/// Identifies the <seealso cref="IsEnabledValue"/> avalonia property.
/// </summary>
public static readonly StyledProperty<bool> IsEnabledValueProperty =
AvaloniaProperty.Register<SetEnabledAction, bool>(nameof(IsEnabledValue), true);

/// <summary>
/// Gets or sets the target control. This is an avalonia property.
/// </summary>
[ResolveByName]
public Control? TargetControl
{
get => GetValue(TargetControlProperty);
set => SetValue(TargetControlProperty, value);
}

/// <summary>
/// Gets or sets the value to assign to <see cref="Control.IsEnabled"/>.

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved

Check warning on line 35 in src/Avalonia.Xaml.Interactions.Custom/Actions/SetEnabledAction.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

XML comment has cref attribute 'IsEnabled' that could not be resolved
/// This is an avalonia property.
/// </summary>
public bool IsEnabledValue
{
get => GetValue(IsEnabledValueProperty);
set => SetValue(IsEnabledValueProperty, value);
}

/// <summary>
/// Executes the action.
/// </summary>
/// <param name="sender">The <see cref="object"/> that is passed to the action by the behavior.</param>
/// <param name="parameter">The value of this parameter is determined by the caller.</param>
/// <returns>True if the property is successfully updated; else false.</returns>
public override object Execute(object? sender, object? parameter)
{
if (!IsEnabled)
{
return false;
}

var control = TargetControl ?? sender as Control;
if (control is null)
{
return false;
}

control.SetCurrentValue(InputElement.IsEnabledProperty, IsEnabledValue);
return true;
}
}
Loading