-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentPageUtil.cs
63 lines (54 loc) · 1.55 KB
/
ContentPageUtil.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
using MauiIssues.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MauiIssues
{
public class ContentPageUtil<T> where T : BaseViewModel, new()
{
private T _pageBindingContext;
private ContentPage _page;
public T PageBindingContext
{
get { return _pageBindingContext; }
set { _pageBindingContext = value; }
}
public ContentPageUtil(ContentPage page, T viewModel)
{
_page = page;
_pageBindingContext = viewModel;
_page.NavigatedTo += _pageBindingContext.NavigatedTo;
_page.Appearing += _pageBindingContext.Appearing;
}
public void OnAppearing()
{
AnimateFadeIn();
}
public void Dismiss()
{
MainThread.BeginInvokeOnMainThread(() =>
{
AnimateFadeOutAndPop();
});
}
public void AnimateFadeIn()
{
MainThread.BeginInvokeOnMainThread(() =>
{
_page.Content.Opacity = 0;
_page.Content.FadeTo(1.0, 150, Easing.Linear);
});
}
public void AnimateFadeOutAndPop()
{
MainThread.BeginInvokeOnMainThread(async () =>
{
// Animate to fade out
await _page.Content.FadeTo(0, 150, Easing.Linear);
await _page.Navigation.PopModalAsync(false);
});
}
}
}