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

37 lines
1.4 KiB
C#

using System.Reactive.Disposables;
using System.Windows;
using System.Windows.Controls;
using Intromat.Interfaces;
using Intromat.ViewModels.Editors;
using ReactiveUI;
namespace Intromat.Views.Editors
{
[TemplatePart(Name = nameof(_sliderValue), Type = typeof(Slider))]
[TemplatePart(Name = nameof(_textBoxValue), Type = typeof(TextBox))]
public class IntegerValueEditorView : EditorViewBase<IntegerValueEditorViewModel>
{
private Slider _sliderValue = null!;
private TextBox _textBoxValue = null!;
public IntegerValueEditorView()
{
DefaultStyleKey = typeof(IntegerValueEditorView);
this.WhenActivated(d =>
{
this.Bind(ViewModel, vm => vm.Value, v => v._textBoxValue.Text).DisposeWith(d);
this.Bind(ViewModel, vm => vm.Value, 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))!;
_textBoxValue = (TextBox)GetTemplateChild(nameof(_textBoxValue))!;
}
}
}