Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Use xaml user control
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Jul 26, 2023
1 parent 059f050 commit cf16698
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Avalonia.Xaml.Interactions.UnitTests.Core.ChangePropertyAction001"
Title="ChangePropertyAction001">
<StackPanel>
<TextBox Name="TargetTextBox" Text="Initial Text" />
<Button Name="TargetButton">
<Interaction.Behaviors>
<EventTriggerBehavior EventName="Click">
<ChangePropertyAction TargetObject="TargetTextBox"
PropertyName="Text"
Value="Updated Text" />
</EventTriggerBehavior>
</Interaction.Behaviors>
</Button>
</StackPanel>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia.Controls;

namespace Avalonia.Xaml.Interactions.UnitTests.Core;

public partial class ChangePropertyAction001 : Window
{
public ChangePropertyAction001()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -1,61 +1,23 @@
using Avalonia.Controls;
using Avalonia.Headless;
using Avalonia.Headless;
using Avalonia.Headless.XUnit;
using Avalonia.Input;
using Avalonia.Xaml.Interactions.Core;
using Avalonia.Xaml.Interactivity;
using Xunit;

namespace Avalonia.Xaml.Interactions.UnitTests.Core;

public class ChangePropertyActionTests
{
[AvaloniaFact]
public void Should_Update_Text_Property_On_Click_Event()
public void ChangePropertyAction_001()
{
var textBox = new TextBox
{
Text = "Initial Text"
};

var button = new Button
{
[Interaction.BehaviorsProperty] = new BehaviorCollection
{
new EventTriggerBehavior
{
EventName = "Click",
Actions =
{
new ChangePropertyAction
{
TargetObject = textBox,
PropertyName = "Text",
Value = "Updated Text"
}
}
}
}
};

var window = new Window
{
Content = new StackPanel
{
Children =
{
textBox,
button
}
}
};
var window = new ChangePropertyAction001();

window.Show();

// Click
button.Focus();
window.TargetButton.Focus();
window.KeyPress(Key.Enter, RawInputModifiers.None);

Assert.Equal("Updated Text", textBox.Text);
Assert.Equal("Updated Text", window.TargetTextBox.Text);
}
}

0 comments on commit cf16698

Please sign in to comment.