-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainPage.cs
48 lines (43 loc) · 1.71 KB
/
MainPage.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
using System;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Fluent;
namespace FluentLayoutSample
{
public class MainPage : ContentPage
{
public MainPage()
{
Content = new AbsoluteLayout().SetChildren(
new BoxView
{
Color = Color.Purple
}.SetAbsoluteLayout(AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional, 0, 1, 1, 80),
new Label
{
TranslationY = -40
}.BindTextLabel(nameof(MainViewModel.Text))
.SetAbsoluteLayout(AbsoluteLayoutFlags.PositionProportional, .5, 1, -1, 80),
new StackLayout().SetChildren(
new Button()
.BindTextButton(nameof(MainViewModel.ButtonTitle))
.BindCommandButton(nameof(MainViewModel.ClickCommand)),
new Label
{
// Blue will never appear, as the binding will be triggering the
// PropertyChanged event handler
BackgroundColor = Color.Blue
}
.BindTextLabel(nameof(MainViewModel.Label))
.WithLabelPropertyChangedEvent(HandlePropertyChangedEvent)
).SetAbsoluteLayout(AbsoluteLayoutFlags.PositionProportional, .5, .5)
);
BindingContext = new MainViewModel();
}
private void HandlePropertyChangedEvent(object sender, PropertyChangedEventArgs e)
{
var label = sender as Label;
label.BackgroundColor = Color.Red;
}
}
}