-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAvaloniaView.cs
60 lines (46 loc) · 1.31 KB
/
AvaloniaView.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
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Embedding;
using Avalonia.Platform;
namespace Xamarin.Mac.Interop;
public class AvaloniaView : IDisposable
{
private readonly EmbeddableControlRoot _topLevel;
private Control? _content;
public AvaloniaView()
{
_topLevel = new EmbeddableControlRoot();
var platformHandle = _topLevel.TryGetPlatformHandle();
if (platformHandle is IMacOSTopLevelPlatformHandle handle)
{
AvnView = ObjCRuntime.Runtime.GetNSObject(handle.NSView) as NSView;
}
}
public NSView? AvnView { get; }
public Control? Content
{
get => _content;
set
{
_content = value;
_topLevel.Content = _content;
if (_content is null)
{
return;
}
_content.Measure(Size.Infinity);
AvnView?.SetFrameSize(new CGSize(_content.DesiredSize.Width, _content.DesiredSize.Height));
_topLevel.Prepare();
}
}
public void Start()
{
_topLevel.StartRendering();
}
public void Dispose()
{
_topLevel.StopRendering();
_topLevel.Dispose();
AvnView?.Dispose();
}
}