Files
bluflame/intromat/Intromat/Views/Editors/DimensionEditorView.cs
2026-04-18 22:31:51 +02:00

38 lines
1.5 KiB
C#

using System.Reactive.Disposables;
using System.Windows;
using System.Windows.Controls;
using Intromat.Interfaces;
using Intromat.Nodes.Code;
using Intromat.ViewModels.Editors;
using ReactiveUI;
namespace Intromat.Views.Editors
{
[TemplatePart(Name = nameof(_sliderValue), Type = typeof(Slider))]
[TemplatePart(Name = nameof(_textBlockValue), Type = typeof(TextBlock))]
public class DimensionEditorView : EditorViewBase<DimensionEditorViewModel>
{
private Slider _sliderValue = null!;
private TextBlock _textBlockValue = null!;
public DimensionEditorView()
{
DefaultStyleKey = typeof(DimensionEditorView);
this.WhenActivated(d =>
{
this.OneWayBind(ViewModel, vm => vm.Value, v => v._textBlockValue.Text, v => ((IntLiteralValue?)v)?.EvaluateDimension().ToString() ?? "0").DisposeWith(d);
this.Bind(ViewModel, vm => vm.CustomValue, v => v._sliderValue.Value, i => i, v => (int)v).DisposeWith(d);
this.Bind(ViewModel, vm => vm.MinValue, v => v._sliderValue.Minimum, i => i, v => (int)v).DisposeWith(d);
this.Bind(ViewModel, vm => vm.MaxValue, v => v._sliderValue.Maximum, i => i, v => (int)v).DisposeWith(d);
});
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_sliderValue = (Slider)GetTemplateChild(nameof(_sliderValue))!;
_textBlockValue = (TextBlock)GetTemplateChild(nameof(_textBlockValue))!;
}
}
}