mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Node editor - Added node creation by dropping cables in empty space
Node editor - Added undo/redo to static value nodes UI - Throw exception when binding a non-reactive view to an activatable view model
This commit is contained in:
1 parent
06ab2c5bb6
commit
2ae1f5f56c
31 files changed
+630
-253
No files matched your search
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Xaml.Interactivity;
|
||||
|
||||
namespace Artemis.UI.Shared.Behaviors;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a behavior that can be used to make a text box only update it's binding on focus loss.
|
||||
/// </summary>
|
||||
public class LostFocusTextBoxBindingBehavior : Behavior<TextBox>
|
||||
{
|
||||
public static readonly StyledProperty<string> TextProperty = AvaloniaProperty.Register<LostFocusTextBoxBindingBehavior, string>(
|
||||
"Text", defaultBindingMode: BindingMode.TwoWay);
|
||||
|
||||
static LostFocusTextBoxBindingBehavior()
|
||||
{
|
||||
TextProperty.Changed.Subscribe(e => ((LostFocusTextBoxBindingBehavior) e.Sender).OnBindingValueChanged());
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => GetValue(TextProperty);
|
||||
set => SetValue(TextProperty, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnAttached()
|
||||
{
|
||||
if (AssociatedObject != null)
|
||||
AssociatedObject.LostFocus += OnLostFocus;
|
||||
base.OnAttached();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
if (AssociatedObject != null)
|
||||
AssociatedObject.LostFocus -= OnLostFocus;
|
||||
base.OnDetaching();
|
||||
}
|
||||
|
||||
private void OnLostFocus(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (AssociatedObject != null)
|
||||
Text = AssociatedObject.Text;
|
||||
}
|
||||
|
||||
private void OnBindingValueChanged()
|
||||
{
|
||||
if (AssociatedObject != null)
|
||||
AssociatedObject.Text = Text;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user