/
XamlApp.xaml.cs
61 lines (50 loc) · 1.42 KB
/
XamlApp.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
54
55
56
57
58
59
60
61
using System;
using System.Diagnostics;
using System.IO;
using Maui.Controls.Sample.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Storage;
namespace Maui.Controls.Sample
{
public partial class XamlApp : Application
{
public XamlApp(IServiceProvider services, ITextService textService)
{
InitializeComponent();
Services = services;
Debug.WriteLine($"The injected text service had a message: '{textService.GetText()}'");
Debug.WriteLine($"Current app theme: {RequestedTheme}");
RequestedThemeChanged += (sender, args) =>
{
// Respond to the theme change
Debug.WriteLine($"Requested theme changed: {args.RequestedTheme}");
};
LoadAsset();
}
async void LoadAsset()
{
try
{
using var stream = await FileSystem.OpenAppPackageFileAsync("RawAsset.txt");
using var reader = new StreamReader(stream);
Debug.WriteLine($"The raw Maui asset contents: '{reader.ReadToEnd().Trim()}'");
}
catch (Exception ex)
{
Debug.WriteLine($"Error loading the raw Maui asset contents: {ex}");
}
}
// Must not use MainPage for multi-window
protected override Window CreateWindow(IActivationState activationState)
{
var window = new MauiWindow(Services.GetRequiredService<Page>())
{
Title = ".NET MAUI Samples Gallery"
};
return window;
}
public IServiceProvider Services { get; }
}
}