diff options
author | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-10-07 21:44:32 -0300 |
---|---|---|
committer | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-10-07 21:44:32 -0300 |
commit | 94b670d6383e1f7dd2a43a500e760b74fc832820 (patch) | |
tree | 30208d27f56ff8ae818b0f2f9b77d7951f3d7cdf | |
parent | b8fd0c3b74d5a7c9db92c187daddfdf2a3add4c9 (diff) |
Initial version of demo MVVM appdevs/lauromoura/csharp-mvvm
For now, a static model with a simple CollectionView
-rw-r--r-- | apps/csharp/mvvm-example/src/mvvm_basic.cs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/apps/csharp/mvvm-example/src/mvvm_basic.cs b/apps/csharp/mvvm-example/src/mvvm_basic.cs new file mode 100644 index 00000000..74199e67 --- /dev/null +++ b/apps/csharp/mvvm-example/src/mvvm_basic.cs | |||
@@ -0,0 +1,83 @@ | |||
1 | using System; | ||
2 | |||
3 | class WeatherStation | ||
4 | { | ||
5 | public String Nick { get; set; } | ||
6 | public float Temperature { get; set; } | ||
7 | |||
8 | public static Efl.UserModel<WeatherStation> CreateModel(Efl.Loop loop) | ||
9 | { | ||
10 | Efl.UserModel<WeatherStation> stations = new Efl.UserModel<WeatherStation>(loop); | ||
11 | stations.Add (new WeatherStation{ Nick="FLN", Temperature=20 }); | ||
12 | stations.Add (new WeatherStation{ Nick="SAO", Temperature=25 }); | ||
13 | stations.Add (new WeatherStation{ Nick="RIO", Temperature=35 }); | ||
14 | stations.Add (new WeatherStation{ Nick="BSB", Temperature=30 }); | ||
15 | |||
16 | return stations; | ||
17 | } | ||
18 | } | ||
19 | |||
20 | class WeatherServer | ||
21 | { | ||
22 | } | ||
23 | |||
24 | class Application : Efl.Csharp.Application | ||
25 | { | ||
26 | private Efl.Ui.Win win; | ||
27 | |||
28 | protected override void OnInitialize(string[] args) | ||
29 | { | ||
30 | win = new Efl.Ui.Win(parent: null, winName: "MVVM Example", | ||
31 | winType: Efl.Ui.WinType.Basic); | ||
32 | win.SetText("EFL Life"); | ||
33 | win.SetAutohide(true); | ||
34 | |||
35 | win.VisibilityChangedEvent += QuitEvt; | ||
36 | |||
37 | |||
38 | var factory = new Efl.Ui.ItemFactory<Efl.Ui.ListDefaultItem>(win); | ||
39 | /* factory.TextPart().Markup().Bind("Nick"); */ | ||
40 | factory.BindProperty("text", "Nick"); | ||
41 | |||
42 | var model = WeatherStation.CreateModel(Efl.App.AppMain); | ||
43 | model.SetProperty("item.width", 1); | ||
44 | model.SetProperty("item.height", 1); | ||
45 | |||
46 | Console.WriteLine($"Width: {model.GetProperty("item.width")}"); | ||
47 | |||
48 | /* var list = new Efl.Ui.ListView(box); */ | ||
49 | |||
50 | /* list.LayoutFactory = factory; */ | ||
51 | /* list.Model = model; */ | ||
52 | |||
53 | var manager = new Efl.Ui.PositionManager.List(win); | ||
54 | var list = new Efl.Ui.CollectionView(win); | ||
55 | |||
56 | Eina.Log.Error("Setting manager"); | ||
57 | list.PositionManager = manager; | ||
58 | Eina.Log.Error("Setting model"); | ||
59 | list.Model = model; | ||
60 | Eina.Log.Error("Setting factory"); | ||
61 | list.Factory = factory; | ||
62 | |||
63 | /* var box = new Efl.Ui.Box(win); */ | ||
64 | /* box.PackEnd(list); */ | ||
65 | win.SetContent(list); | ||
66 | win.SetSize(new Eina.Size2D(640, 480)); | ||
67 | win.Visible = true; | ||
68 | } | ||
69 | |||
70 | void QuitEvt(object sender, Efl.Gfx.EntityVisibilityChangedEventArgs ev) | ||
71 | { | ||
72 | if (ev.arg == false) | ||
73 | { | ||
74 | Efl.App.AppMain.Quit(0); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | public static void Main() | ||
79 | { | ||
80 | var app = new Application(); | ||
81 | app.Launch(); | ||
82 | } | ||
83 | } | ||