forked from dylanberry/XamarinDynamicUI
/
MainPageCSharpMarkup.cs
47 lines (40 loc) · 1.83 KB
/
MainPageCSharpMarkup.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
using Xamarin.Forms;
using Xamarin.Forms.Markup;
using static Xamarin.Forms.Markup.Factory;
using static XamlFlags.Colors;
using Option = XamlFlags.OptionViewModel;
namespace XamlFlags
{
// This is the most straightforward implementation of MainPage in C# Markup,
// using Fody PropertyChanged to automatically make calculated properties data bindable.
partial class MainPageCSharpMarkup
{
void Build() => Content =
VStack (() =>
Frame (
HStack (
Button ("Select")
.BindCommand (nameof(vm.SelectTypeCommand), source: vm),
Label ("✓")
.TextColor (White) .FontSize (12)
.EndExpand () .CenterVertical ()
.IsVisible().Bind (nameof(Option.IsSelected)),
Label ()
.TextColor().Bind (nameof(Option.TextColor))
.EndExpand () .CenterVertical ()
.Bind (nameof(Option.Value))
) .Color().Bind (nameof(Option.BackgroundColor))
.Padding (5)
.IsEnabled().Bind (nameof(Option.IsEnabled))
) .CornerRadius (4) .Padding (0)
) .ItemsSource (vm.Options);
}
partial class OptionViewModel
{
public Color TextColor => IsEnabled ? (IsSelected ? White : Black) : LightGray;
public Color BackgroundColor => IsEnabled ? (IsSelected ? DarkBlue : White) : DarkGray;
}
// Note that in contrast to Blazor, which only updates in response to UI events,
// this will also update correctly when the data is changed from background events
// (e.g. data coming in from an API)
}