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.
78 lines
2.5 KiB
78 lines
2.5 KiB
using System.Collections.Generic;
|
|
using System.Reactive;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Controls;
|
|
using Avalonia.VisualTree;
|
|
using MiniMvvm;
|
|
|
|
namespace ControlCatalog.ViewModels
|
|
{
|
|
public class ContextFlyoutPageViewModel
|
|
{
|
|
public Control View { get; set; }
|
|
public ContextFlyoutPageViewModel()
|
|
{
|
|
OpenCommand = MiniCommand.CreateFromTask(Open);
|
|
SaveCommand = MiniCommand.Create(Save);
|
|
OpenRecentCommand = MiniCommand.Create<string>(OpenRecent);
|
|
|
|
MenuItems = new[]
|
|
{
|
|
new MenuItemViewModel { Header = "_Open...", Command = OpenCommand },
|
|
new MenuItemViewModel { Header = "Save", Command = SaveCommand },
|
|
new MenuItemViewModel { Header = "-" },
|
|
new MenuItemViewModel
|
|
{
|
|
Header = "Recent",
|
|
Items = new[]
|
|
{
|
|
new MenuItemViewModel
|
|
{
|
|
Header = "File1.txt",
|
|
Command = OpenRecentCommand,
|
|
CommandParameter = @"c:\foo\File1.txt"
|
|
},
|
|
new MenuItemViewModel
|
|
{
|
|
Header = "File2.txt",
|
|
Command = OpenRecentCommand,
|
|
CommandParameter = @"c:\foo\File2.txt"
|
|
},
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
public IReadOnlyList<MenuItemViewModel> MenuItems { get; set; }
|
|
public MiniCommand OpenCommand { get; }
|
|
public MiniCommand SaveCommand { get; }
|
|
public MiniCommand OpenRecentCommand { get; }
|
|
|
|
public async Task Open()
|
|
{
|
|
var window = View?.GetVisualRoot() as Window;
|
|
if (window == null)
|
|
return;
|
|
var dialog = new OpenFileDialog();
|
|
var result = await dialog.ShowAsync(window);
|
|
|
|
if (result != null)
|
|
{
|
|
foreach (var path in result)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"Opened: {path}");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
System.Diagnostics.Debug.WriteLine("Save");
|
|
}
|
|
|
|
public void OpenRecent(string path)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"Open recent: {path}");
|
|
}
|
|
}
|
|
}
|
|
|