forked from VladislavAntonyuk/MauiSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
53 lines (48 loc) · 1.48 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
namespace MauiPaint;
using System.Windows.Input;
using Microsoft.Maui.Platform;
public partial class MainPage : ContentPage
{
#if MACCATALYST || WINDOWS
private readonly MainPageViewModel mainPageViewModel;
#endif
public MainPage(MainPageViewModel mainPageViewModel, IDeviceInfo deviceInfo)
{
InitializeComponent();
if (deviceInfo.Platform == DevicePlatform.Android || deviceInfo.Platform == DevicePlatform.iOS)
{
AddToolbarItem("New", mainPageViewModel.NewCommand);
AddToolbarItem("Open", mainPageViewModel.OpenCommand);
AddToolbarItem("Save Project", mainPageViewModel.SaveCommand);
AddToolbarItem("Save Image", mainPageViewModel.SaveImageCommand);
AddToolbarItem("Toggle Theme", mainPageViewModel.ToggleThemeCommand);
AddToolbarItem("Help", mainPageViewModel.HelpCommand);
AddToolbarItem("About", mainPageViewModel.AboutCommand);
}
BindingContext = mainPageViewModel;
#if MACCATALYST || WINDOWS
this.mainPageViewModel = mainPageViewModel;
Loaded += MainPage_Loaded;
}
private void MainPage_Loaded(object? sender, EventArgs e)
{
if (Handler?.MauiContext != null)
{
var uiElement = this.ToPlatform(Handler.MauiContext);
DragDropHelper.RegisterDragDrop(uiElement, async stream =>
{
await mainPageViewModel.OpenFile(stream, CancellationToken.None);
});
}
#endif
}
void AddToolbarItem(string text, ICommand command)
{
var toolbarItem = new ToolbarItem()
{
Text = text,
Command = command
};
ToolbarItems.Add(toolbarItem);
}
}