/
Forms.cs
68 lines (53 loc) · 2.01 KB
/
Forms.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
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows.Media;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform.WPF;
namespace Xamarin.Forms
{
public static class Forms
{
public static bool IsInitialized { get; private set; }
static bool FlagsSet { get; set; }
static IReadOnlyList<string> s_flags;
public static IReadOnlyList<string> Flags => s_flags ?? (s_flags = new List<string>().AsReadOnly());
public static void Init(IEnumerable<Assembly> rendererAssemblies = null)
{
if (IsInitialized)
return;
string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
System.Windows.Application.Current.Resources.MergedDictionaries.Add(new System.Windows.ResourceDictionary
{
Source = new Uri(string.Format("/{0};component/WPFResources.xaml", assemblyName), UriKind.Relative)
});
var accentColor = (SolidColorBrush)System.Windows.Application.Current.Resources["AccentColor"];
Color.SetAccent(Color.FromRgba(accentColor.Color.R, accentColor.Color.G, accentColor.Color.B, accentColor.Color.A));
Log.Listeners.Add(new DelegateLogListener((c, m) => Console.WriteLine("[{0}] {1}", m, c)));
Registrar.ExtraAssemblies = rendererAssemblies?.ToArray();
Device.SetTargetIdiom(TargetIdiom.Desktop);
Device.PlatformServices = new WPFPlatformServices();
Device.Info = new WPFDeviceInfo();
ExpressionSearch.Default = new WPFExpressionSearch();
Registrar.RegisterAll(new[] { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute) });
Ticker.SetDefault(new WPFTicker());
Device.SetIdiom(TargetIdiom.Desktop);
Device.SetFlags(s_flags);
IsInitialized = true;
}
public static void SetFlags(params string[] flags)
{
if (FlagsSet)
{
return;
}
if (IsInitialized)
{
throw new InvalidOperationException($"{nameof(SetFlags)} must be called before {nameof(Init)}");
}
s_flags = flags.ToList().AsReadOnly();
FlagsSet = true;
}
}
}