From a294382c7d6d73c8253fb9e2caffebafae3dda42 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sun, 16 Sep 2018 16:09:11 +0200 Subject: [PATCH] Fix: Button data binding --- .../BasicElements/Text/CUiElementText.cs | 11 ++++++- Vocaluxe.UI/DummyClass.cs | 32 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Vocaluxe.UI/BasicElements/Text/CUiElementText.cs b/Vocaluxe.UI/BasicElements/Text/CUiElementText.cs index 41abe4b3..b769a52b 100644 --- a/Vocaluxe.UI/BasicElements/Text/CUiElementText.cs +++ b/Vocaluxe.UI/BasicElements/Text/CUiElementText.cs @@ -17,7 +17,16 @@ namespace Vocaluxe.UI.BasicElements.Text { var instance = CUiElement.CreateInstance(properties, children); properties.TryGetValue("value", out string value); - instance.Controller.Text = value; + + if (properties.ContainsKey("bindingid")) + { + instance.Controller.Text = DummyClass.RegisterBinding(properties["bindingid"], (sender, s) => instance.Controller.Text = s); + } + else + { + instance.Controller.Text = value; + } + return instance; } } diff --git a/Vocaluxe.UI/DummyClass.cs b/Vocaluxe.UI/DummyClass.cs index b04a90c2..593985f1 100644 --- a/Vocaluxe.UI/DummyClass.cs +++ b/Vocaluxe.UI/DummyClass.cs @@ -1,4 +1,6 @@ -using Vocaluxe.UI.Screens; +using System; +using System.Collections.Generic; +using Vocaluxe.UI.Screens; namespace Vocaluxe.UI { @@ -6,5 +8,33 @@ namespace Vocaluxe.UI { // Should be somewhere in Vocaluxe public static EUiScreenType CurrentScreen => EUiScreenType.ScreenMain; + + private static readonly Dictionary StringData = new Dictionary() + { + {"btnsingdescription", "Sing"}, + {"btnpartydescription", "Party"}, + {"btnoptionsdescription", "Options"}, + {"btnprofilesdescription", "Profiles"}, + {"btnexitdescription", "Exit"}, + + }; + private static readonly Dictionary IntData = new Dictionary(); + + public static T RegisterBinding(string bindingId, EventHandler eventHandler) + { + // eventHandler is used to notify about changes -> not implemented yet + + switch (typeof(T).ToString()) + { + case "System.String": + StringData.TryGetValue(bindingId.ToLower(), out string stringResult); + return (T)Convert.ChangeType(stringResult, typeof(T)); + case "System.Int32": + IntData.TryGetValue(bindingId.ToLower(), out int intResult); + return (T)Convert.ChangeType(intResult, typeof(T)); + } + + return default(T); + } } }