-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from wieslawsoltes/AddNewTriggers
Add new event triggers
- Loading branch information
Showing
54 changed files
with
1,287 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
samples/BehaviorsTestApplication/ViewModels/PointerTriggersViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Windows.Input; | ||
using ReactiveUI; | ||
|
||
namespace BehaviorsTestApplication.ViewModels; | ||
|
||
public partial class PointerTriggersViewModel : ViewModelBase | ||
{ | ||
public PointerTriggersViewModel() | ||
{ | ||
PointerPressedCommand = ReactiveCommand.Create<(double X, double Y)>(PointerPressed); | ||
PointerReleasedCommand = ReactiveCommand.Create<(double X, double Y)>(PointerReleased); | ||
PointerMovedCommand = ReactiveCommand.Create<(double X, double Y)>(PointerMoved); | ||
} | ||
|
||
public ICommand PointerPressedCommand { get; set; } | ||
|
||
public ICommand PointerReleasedCommand { get; set; } | ||
|
||
public ICommand PointerMovedCommand { get; set; } | ||
|
||
private void PointerPressed((double X, double Y) point) | ||
{ | ||
Console.WriteLine($"Pressed: {point}"); | ||
} | ||
|
||
private void PointerReleased((double X, double Y) point) | ||
{ | ||
Console.WriteLine($"Released: {point}"); | ||
} | ||
|
||
private void PointerMoved((double X, double Y) point) | ||
{ | ||
Console.WriteLine($"Moved: {point}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
samples/BehaviorsTestApplication/Views/Pages/PointerTriggersView.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<UserControl x:Class="BehaviorsTestApplication.Views.Pages.PointerTriggersView" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:vm="using:BehaviorsTestApplication.ViewModels" | ||
x:DataType="vm:PointerTriggersViewModel" | ||
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"> | ||
<Design.DataContext> | ||
<vm:PointerTriggersViewModel /> | ||
</Design.DataContext> | ||
|
||
<Canvas Width="500" Height="500" Background="WhiteSmoke"> | ||
<Interaction.Behaviors> | ||
<PointerPressedTrigger EventRoutingStrategy="Bubble"> | ||
<CapturePointerAction /> | ||
<InvokeCommandAction Command="{Binding PointerPressedCommand}" | ||
InputConverter="{PointerEventArgsConverter}" /> | ||
</PointerPressedTrigger> | ||
<PointerReleasedTrigger EventRoutingStrategy="Bubble"> | ||
<ReleasePointerCaptureAction /> | ||
<InvokeCommandAction Command="{Binding PointerReleasedCommand}" | ||
InputConverter="{PointerEventArgsConverter}" /> | ||
</PointerReleasedTrigger> | ||
<PointerMovedTrigger EventRoutingStrategy="Bubble"> | ||
<InvokeCommandAction Command="{Binding PointerMovedCommand}" | ||
InputConverter="{PointerEventArgsConverter}" /> | ||
</PointerMovedTrigger> | ||
</Interaction.Behaviors> | ||
</Canvas> | ||
|
||
</UserControl> |
17 changes: 17 additions & 0 deletions
17
samples/BehaviorsTestApplication/Views/Pages/PointerTriggersView.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace BehaviorsTestApplication.Views.Pages; | ||
|
||
public partial class PointerTriggersView : UserControl | ||
{ | ||
public PointerTriggersView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/Avalonia.Xaml.Interactions.Custom/Converters/PointerEventArgsConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Globalization; | ||
using Avalonia.Data.Converters; | ||
using Avalonia.Input; | ||
|
||
namespace Avalonia.Xaml.Interactions.Custom.Converters; | ||
|
||
/// <summary> | ||
/// Converter for <see cref="PointerEventArgs"/>. | ||
/// </summary> | ||
public class PointerEventArgsConverter : IValueConverter | ||
{ | ||
/// <summary> | ||
/// Gets the instance of <see cref="PointerEventArgsConverter"/>. | ||
/// </summary> | ||
public static readonly PointerEventArgsConverter Instance = new(); | ||
|
||
/// <inheritdoc /> | ||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
switch (value) | ||
{ | ||
case PointerPressedEventArgs pointerPressedEventArgs: | ||
{ | ||
if (pointerPressedEventArgs.Source is not Visual visual) | ||
{ | ||
return AvaloniaProperty.UnsetValue; | ||
} | ||
|
||
var (x, y) = pointerPressedEventArgs.GetPosition(visual); | ||
|
||
return (x, y); | ||
} | ||
case PointerReleasedEventArgs pointerReleasedEventArgs: | ||
{ | ||
if (pointerReleasedEventArgs.Source is not Visual visual) | ||
{ | ||
return AvaloniaProperty.UnsetValue; | ||
} | ||
|
||
var (x, y) = pointerReleasedEventArgs.GetPosition(visual); | ||
|
||
return (x, y); | ||
} | ||
case PointerDeltaEventArgs pointerDeltaEventArgs: | ||
{ | ||
var (x, y) = pointerDeltaEventArgs.Delta; | ||
|
||
return (x, y); | ||
} | ||
case PointerWheelEventArgs pointerWheelEventArgs: | ||
{ | ||
var (x, y) = pointerWheelEventArgs.Delta; | ||
|
||
return (x, y); | ||
} | ||
case PointerEventArgs pointerEventArgs: | ||
{ | ||
if (pointerEventArgs.Source is not Visual visual) | ||
{ | ||
return AvaloniaProperty.UnsetValue; | ||
} | ||
|
||
var (x, y) = pointerEventArgs.GetPosition(visual); | ||
|
||
return (x, y); | ||
} | ||
default: | ||
return AvaloniaProperty.UnsetValue; | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
return AvaloniaProperty.UnsetValue; | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="serviceProvider"></param> | ||
/// <returns></returns> | ||
public IValueConverter ProvideValue(IServiceProvider serviceProvider) => Instance; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Avalonia.Xaml.Interactions.Custom/Core/ActualThemeVariantChangedTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Avalonia.Xaml.Interactivity; | ||
|
||
namespace Avalonia.Xaml.Interactions.Custom; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class ActualThemeVariantChangedTrigger : StyledElementTrigger<StyledElement> | ||
{ | ||
/// <inheritdoc /> | ||
protected override void OnActualThemeVariantChangedEvent() | ||
{ | ||
if (!IsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
Interaction.ExecuteActions(AssociatedObject, Actions, parameter: null); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Avalonia.Xaml.Interactions.Custom/Core/AttachedToLogicalTreeTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Avalonia.Xaml.Interactivity; | ||
|
||
namespace Avalonia.Xaml.Interactions.Custom; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class AttachedToLogicalTreeTrigger : StyledElementTrigger<StyledElement> | ||
{ | ||
/// <inheritdoc /> | ||
protected override void OnAttachedToLogicalTree() | ||
{ | ||
if (!IsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
Interaction.ExecuteActions(AssociatedObject, Actions, parameter: null); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Avalonia.Xaml.Interactions.Custom/Core/AttachedToVisualTreeTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Avalonia.Xaml.Interactivity; | ||
|
||
namespace Avalonia.Xaml.Interactions.Custom; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class AttachedToVisualTreeTrigger : StyledElementTrigger<Visual> | ||
{ | ||
/// <inheritdoc /> | ||
protected override void OnAttachedToVisualTree() | ||
{ | ||
if (!IsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
Interaction.ExecuteActions(AssociatedObject, Actions, parameter: null); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Avalonia.Xaml.Interactions.Custom/Core/DataContextChangedTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Avalonia.Xaml.Interactivity; | ||
|
||
namespace Avalonia.Xaml.Interactions.Custom; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class DataContextChangedTrigger : StyledElementTrigger<StyledElement> | ||
{ | ||
/// <inheritdoc /> | ||
protected override void OnDataContextChangedEvent() | ||
{ | ||
if (!IsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
Interaction.ExecuteActions(AssociatedObject, Actions, parameter: null); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Avalonia.Xaml.Interactions.Custom/Core/DetachedFromLogicalTreeTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Avalonia.Xaml.Interactivity; | ||
|
||
namespace Avalonia.Xaml.Interactions.Custom; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class DetachedFromLogicalTreeTrigger : StyledElementTrigger<StyledElement> | ||
{ | ||
/// <inheritdoc /> | ||
protected override void OnDetachedFromLogicalTree() | ||
{ | ||
if (!IsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
Interaction.ExecuteActions(AssociatedObject, Actions, parameter: null); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Avalonia.Xaml.Interactions.Custom/Core/DetachedFromVisualTreeTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Avalonia.Xaml.Interactivity; | ||
|
||
namespace Avalonia.Xaml.Interactions.Custom; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class DetachedFromVisualTreeTrigger : StyledElementTrigger<Visual> | ||
{ | ||
/// <inheritdoc /> | ||
protected override void OnDetachedFromVisualTree() | ||
{ | ||
if (!IsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
Interaction.ExecuteActions(AssociatedObject, Actions, parameter: null); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Avalonia.Xaml.Interactions.Custom/Core/InitializedTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Avalonia.Xaml.Interactivity; | ||
|
||
namespace Avalonia.Xaml.Interactions.Custom; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class InitializedTrigger : StyledElementTrigger<StyledElement> | ||
{ | ||
/// <inheritdoc /> | ||
protected override void OnInitializedEvent() | ||
{ | ||
if (!IsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
Interaction.ExecuteActions(AssociatedObject, Actions, parameter: null); | ||
} | ||
} |
Oops, something went wrong.