Fix: Button data binding

This commit is contained in:
lukeIam committed 2018-09-16 16:09:11 +02:00
1 parent 5e908e2768
commit a294382c7d
2 files changed
+41 -2

No files matched your search

@@ -17,7 +17,16 @@ namespace Vocaluxe.UI.BasicElements.Text
{
var instance = CUiElement.CreateInstance<CUiElementText>(properties, children);
properties.TryGetValue("value", out string value);
instance.Controller.Text = value;
if (properties.ContainsKey("bindingid"))
{
instance.Controller.Text = DummyClass.RegisterBinding<string>(properties["bindingid"], (sender, s) => instance.Controller.Text = s);
}
else
{
instance.Controller.Text = value;
}
return instance;
}
}
+31 -1
View File
@@ -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<string, string> StringData = new Dictionary<string, string>()
{
{"btnsingdescription", "Sing"},
{"btnpartydescription", "Party"},
{"btnoptionsdescription", "Options"},
{"btnprofilesdescription", "Profiles"},
{"btnexitdescription", "Exit"},
};
private static readonly Dictionary<string, int> IntData = new Dictionary<string, int>();
public static T RegisterBinding<T>(string bindingId, EventHandler<T> 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);
}
}
}