csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.9 KiB
126 lines
3.9 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows.Input;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Layout;
|
|
using MiniMvvm;
|
|
|
|
namespace ControlCatalog.ViewModels
|
|
{
|
|
public sealed class FlexViewModel : ViewModelBase
|
|
{
|
|
private readonly ObservableCollection<FlexItemViewModel> _numbers;
|
|
|
|
private FlexDirection _direction = FlexDirection.Row;
|
|
private FlexJustifyContent _justifyContent = FlexJustifyContent.FlexStart;
|
|
private FlexAlignItems _alignItems = FlexAlignItems.FlexStart;
|
|
private FlexAlignContent _alignContent = FlexAlignContent.FlexStart;
|
|
private FlexWrap _wrap = FlexWrap.Wrap;
|
|
|
|
private int _columnSpacing = 64;
|
|
private int _rowSpacing = 32;
|
|
|
|
private int _currentNumber = 41;
|
|
|
|
private FlexItemViewModel? _selectedItem;
|
|
|
|
public FlexViewModel()
|
|
{
|
|
_numbers = new ObservableCollection<FlexItemViewModel>(Enumerable.Range(1, 40).Select(x => new FlexItemViewModel(x)));
|
|
|
|
Numbers = new ReadOnlyObservableCollection<FlexItemViewModel>(_numbers);
|
|
|
|
AddItemCommand = MiniCommand.Create(AddItem);
|
|
RemoveItemCommand = MiniCommand.Create(RemoveItem);
|
|
}
|
|
|
|
public IEnumerable DirectionValues { get; } = Enum.GetValues<FlexDirection>();
|
|
|
|
public IEnumerable JustifyContentValues { get; } = Enum.GetValues<FlexJustifyContent>();
|
|
|
|
public IEnumerable AlignItemsValues { get; } = Enum.GetValues<FlexAlignItems>();
|
|
|
|
public IEnumerable AlignContentValues { get; } = Enum.GetValues<FlexAlignContent>();
|
|
|
|
public IEnumerable WrapValues { get; } = Enum.GetValues<FlexWrap>();
|
|
|
|
public IEnumerable FlexBasisKindValues { get; } = Enum.GetValues<FlexBasisKind>();
|
|
|
|
public IEnumerable HorizontalAlignmentValues { get; } = Enum.GetValues<HorizontalAlignment>();
|
|
|
|
public IEnumerable VerticalAlignmentValues { get; } = Enum.GetValues<VerticalAlignment>();
|
|
|
|
public IEnumerable AlignSelfValues { get; } = Enum.GetValues<FlexAlignItems>().Cast<FlexAlignItems>().Prepend(FlexItemViewModel.AlignSelfAuto);
|
|
|
|
public FlexDirection Direction
|
|
{
|
|
get => _direction;
|
|
set => this.RaiseAndSetIfChanged(ref _direction, value);
|
|
}
|
|
|
|
public FlexJustifyContent JustifyContent
|
|
{
|
|
get => _justifyContent;
|
|
set => this.RaiseAndSetIfChanged(ref _justifyContent, value);
|
|
}
|
|
|
|
public FlexAlignItems AlignItems
|
|
{
|
|
get => _alignItems;
|
|
set => this.RaiseAndSetIfChanged(ref _alignItems, value);
|
|
}
|
|
|
|
public FlexAlignContent AlignContent
|
|
{
|
|
get => _alignContent;
|
|
set => this.RaiseAndSetIfChanged(ref _alignContent, value);
|
|
}
|
|
|
|
public FlexWrap Wrap
|
|
{
|
|
get => _wrap;
|
|
set => this.RaiseAndSetIfChanged(ref _wrap, value);
|
|
}
|
|
|
|
public int ColumnSpacing
|
|
{
|
|
get => _columnSpacing;
|
|
set => this.RaiseAndSetIfChanged(ref _columnSpacing, value);
|
|
}
|
|
|
|
public int RowSpacing
|
|
{
|
|
get => _rowSpacing;
|
|
set => this.RaiseAndSetIfChanged(ref _rowSpacing, value);
|
|
}
|
|
|
|
public ReadOnlyObservableCollection<FlexItemViewModel> Numbers { get; }
|
|
|
|
public FlexItemViewModel? SelectedItem
|
|
{
|
|
get => _selectedItem;
|
|
set => this.RaiseAndSetIfChanged(ref _selectedItem, value);
|
|
}
|
|
|
|
public ICommand AddItemCommand { get; }
|
|
|
|
public ICommand RemoveItemCommand { get; }
|
|
|
|
private void AddItem() => _numbers.Add(new FlexItemViewModel(_currentNumber++));
|
|
|
|
private void RemoveItem()
|
|
{
|
|
if (SelectedItem is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_numbers.Remove(SelectedItem);
|
|
|
|
SelectedItem.IsSelected = false;
|
|
SelectedItem = null;
|
|
}
|
|
}
|
|
}
|
|
|