9 private const uint durationInMs = 250 / 2;
10 private readonly Easing easingType = Easing.Linear;
12 private readonly Grid contentHolder;
13 private View? frontView;
14 private View? backView;
15 private bool isFading;
22 this.contentHolder =
new Grid { BackgroundColor = Colors.Transparent };
23 this.Content = this.contentHolder;
24 this.BackgroundColor = Colors.Transparent;
31 BindableProperty.Create(nameof(
IsFrontView), typeof(
bool), typeof(
FadeView),
true, propertyChanged: (b, oldValue, newValue) =>
38 fv.FadeFromBackToFront();
40 fv.FadeFromFrontToBack();
58 BindableProperty.Create(nameof(
FrontView), typeof(View), typeof(
FadeView),
default(View), propertyChanged: (b, oldValue, newValue) =>
61 if (newValue is not
null)
63 if (fv.frontView is not
null)
65 fv.contentHolder.Children.Remove(fv.frontView);
67 fv.frontView = (View)newValue;
69 fv.AddChild(fv.frontView);
73 if (fv.frontView is not
null)
75 fv.contentHolder.Children.Remove(fv.frontView);
97 BindableProperty.Create(nameof(
BackView), typeof(View), typeof(
FadeView),
default(View), propertyChanged: (b, oldValue, newValue) =>
100 if (newValue is not
null)
102 if (fv.backView is not
null)
104 fv.contentHolder.Children.Remove(fv.backView);
107 fv.backView = (View)newValue;
108 fv.AddChild(fv.backView);
112 if (fv.backView is not
null)
114 fv.contentHolder.Children.Remove(fv.backView);
132 private void AddChild(View childView)
134 this.contentHolder.Children.Add(childView);
137 private void OrganizeViews()
139 if (this.backView is not
null && this.frontView is not
null)
145 private async
void FadeFromFrontToBack()
147 this.isFading =
true;
149 await this.FadeFrontToBack1();
152 this.OrganizeViews();
154 await this.FadeFrontToBack2();
156 this.isFading =
false;
159 private async
void FadeFromBackToFront()
161 this.isFading =
true;
163 await this.FadeBackToFront1();
166 this.OrganizeViews();
168 await this.FadeBackToFront2();
170 this.isFading =
false;
175 private async Task FadeFrontToBack1()
185 Task.Run(async () => await this.
FrontView.FadeTo(0.5, durationInMs,
this.easingType)),
186 Task.Run(async () => await this.
BackView.FadeTo(0.5, durationInMs,
this.easingType))
189 await Task.WhenAll(tasks);
192 private async Task FadeFrontToBack2()
202 Task.Run(async () => await this.
FrontView.FadeTo(0, durationInMs,
this.easingType)),
203 Task.Run(async () => await this.
BackView.FadeTo(1, durationInMs,
this.easingType))
206 await Task.WhenAll(tasks);
210 private async Task FadeBackToFront1()
220 Task.Run(async () => await this.
FrontView.FadeTo(0.5, durationInMs,
this.easingType)),
221 Task.Run(async () => await this.
BackView.FadeTo(0.5, durationInMs,
this.easingType))
224 await Task.WhenAll(tasks);
227 private async Task FadeBackToFront2()
237 Task.Run(async () => await this.
FrontView.FadeTo(1, durationInMs,
this.easingType)),
238 Task.Run(async () => await this.
BackView.FadeTo(0, durationInMs,
this.easingType))
241 await Task.WhenAll(tasks);
The FadeView is a user control that holds two child controls: a FrontView and a BackView....
FadeView()
Creates an instance of the FadeView control.
View? BackView
The view displayed on the 'back' side of this user control.
bool IsFrontView
Set to true is the front vew must be shown.
static readonly BindableProperty IsFrontViewProperty
View? FrontView
The view displayed on the 'front' side of this user control.
static readonly BindableProperty FrontViewProperty
static readonly BindableProperty BackViewProperty