Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public MainWindowViewModel()
IsLoading = true;
Progress = 30;

DataContextChangedCommand = ReactiveCommand.Create(DataContextChanged);

InitializeCommand = ReactiveCommand.Create(Initialize);

MoveLeftCommand = ReactiveCommand.Create(() => Position -= 5.0);
Expand Down Expand Up @@ -115,6 +117,8 @@ public MainWindowViewModel()

public IObservable<int> Values { get; }

public ICommand DataContextChangedCommand { get; set; }

public ICommand InitializeCommand { get; set; }

public ICommand MoveLeftCommand { get; set; }
Expand All @@ -133,6 +137,11 @@ public MainWindowViewModel()

public ICommand GetClipboardTextCommand { get; set; }

private void DataContextChanged()
{
Console.WriteLine("DataContextChanged");
}

private void Initialize()
{
Console.WriteLine("InitializeCommand");
Expand Down
7 changes: 7 additions & 0 deletions samples/BehaviorsTestApplication/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
Title="XamlBehaviors Test Application" Width="1000" Height="700"
x:DataType="vm:MainWindowViewModel">
<Interaction.Behaviors>

<!-- TopLevel Logical tree special case -->
<!--
<EventTriggerBehavior EventName="Opened">
<InvokeCommandAction Command="{Binding InitializeCommand, Mode=OneTime}" />
</EventTriggerBehavior>
-->

<!-- TopLevel attached to visual tree special case -->
<RoutedEventTriggerBehavior RoutedEvent="{x:Static Control.LoadedEvent}">
<InvokeCommandAction Command="{Binding InitializeCommand, Mode=OneTime}" />
</RoutedEventTriggerBehavior>

<DataContextChangedTrigger>
<InvokeCommandAction Command="{Binding DataContextChangedCommand}" />
</DataContextChangedTrigger>

</Interaction.Behaviors>
<views:MainView />
</Window>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Avalonia.Threading;
using Avalonia.Xaml.Interactivity;

namespace Avalonia.Xaml.Interactions.Custom;
Expand All @@ -10,7 +11,10 @@ public class ActualThemeVariantChangedTrigger : StyledElementTrigger<StyledEleme
/// <inheritdoc />
protected override void OnActualThemeVariantChangedEvent()
{
Execute(parameter: null);
Dispatcher.UIThread.Post(() =>
{
Execute(parameter: null);
});
}

private void Execute(object? parameter)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Avalonia.Threading;
using Avalonia.Xaml.Interactivity;

namespace Avalonia.Xaml.Interactions.Custom;
Expand All @@ -10,7 +11,10 @@ public class DataContextChangedTrigger : StyledElementTrigger<StyledElement>
/// <inheritdoc />
protected override void OnDataContextChangedEvent()
{
Execute(parameter: null);
Dispatcher.UIThread.Post(() =>
{
Execute(parameter: null);
});
}

private void Execute(object? parameter)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Avalonia.Threading;
using Avalonia.Xaml.Interactivity;

namespace Avalonia.Xaml.Interactions.Custom;
Expand All @@ -10,7 +11,10 @@ public class ResourcesChangedTrigger : StyledElementTrigger<StyledElement>
/// <inheritdoc />
protected override void OnResourcesChangedEvent()
{
Execute(parameter: null);
Dispatcher.UIThread.Post(() =>
{
Execute(parameter: null);
});
}

private void Execute(object? parameter)
Expand Down
Loading