feat: initialize, setup demo. make sure MVVM works.

This commit is contained in:
rabbitism
2024-02-21 02:15:30 +08:00
parent 3247a37105
commit 76da0b3616
16 changed files with 313 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
using System.Collections.ObjectModel;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Ursa.Controls;
namespace Ursa.Demo.ViewModels;
public partial class ToolBarDemoViewModel: ObservableObject
{
public ObservableCollection<ToolBarItemViewModel> Items { get; set; }
public ToolBarDemoViewModel()
{
Items = new()
{
new ToolBarButtonItemViewModel() { Content = "New" },
new ToolBarButtonItemViewModel() { Content = "Open" },
new ToolBarButtonItemViewModel() { Content = "Save" },
new ToolBarCheckBoxItemViweModel() { Content = "Bold" },
new ToolBarCheckBoxItemViweModel() { Content = "Italic" },
new ToolBarComboBoxItemViewModel() { Content = "Font Size", Items = new (){ "10", "12", "14" } }
};
}
}
public abstract class ToolBarItemViewModel: ObservableObject
{
}
public class ToolBarButtonItemViewModel: ToolBarItemViewModel
{
public string Content { get; set; }
public ICommand Command { get; set; }
public ToolBarButtonItemViewModel()
{
Command = new AsyncRelayCommand(async () => { await MessageBox.ShowOverlayAsync(Content); });
}
}
public class ToolBarCheckBoxItemViweModel: ToolBarItemViewModel
{
public string Content { get; set; }
public bool IsChecked { get; set; }
public ICommand Command { get; set; }
public ToolBarCheckBoxItemViweModel()
{
Command = new AsyncRelayCommand(async () => { await MessageBox.ShowOverlayAsync(Content); });
}
}
public class ToolBarComboBoxItemViewModel: ToolBarItemViewModel
{
public string Content { get; set; }
public ObservableCollection<string> Items { get; set; }
private string _selectedItem;
public string SelectedItem
{
get => _selectedItem;
set
{
SetProperty(ref _selectedItem, value);
MessageBox.ShowOverlayAsync(value);
}
}
}