diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2021-02-01 22:13:46 -0500 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2021-02-01 22:13:46 -0500 |
| commit | c7428fab1c38d29bcc50ee263678504e34d01318 (patch) | |
| tree | bf5c4a63afc1513d361c6b18fd6c6cf3f0aaaa27 /Erable/ViewLocator.cs | |
| parent | d5f8e3f543e138b43fca95ed058345b9ab446d2f (diff) | |
| download | erable-godot-c7428fab1c38d29bcc50ee263678504e34d01318.tar.gz erable-godot-c7428fab1c38d29bcc50ee263678504e34d01318.tar.bz2 erable-godot-c7428fab1c38d29bcc50ee263678504e34d01318.zip | |
Moved project files
Diffstat (limited to 'Erable/ViewLocator.cs')
| -rw-r--r-- | Erable/ViewLocator.cs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Erable/ViewLocator.cs b/Erable/ViewLocator.cs new file mode 100644 index 0000000..0a6eb01 --- /dev/null +++ b/Erable/ViewLocator.cs @@ -0,0 +1,32 @@ +using System;
+using Avalonia.Controls;
+using Avalonia.Controls.Templates;
+using Erable.ViewModels;
+
+namespace Erable
+{
+ public class ViewLocator : IDataTemplate
+ {
+ public bool SupportsRecycling => false;
+
+ public IControl Build(object data)
+ {
+ var name = data.GetType().FullName!.Replace("ViewModel", "View");
+ var type = Type.GetType(name);
+
+ if (type != null)
+ {
+ return (Control)Activator.CreateInstance(type)!;
+ }
+ else
+ {
+ return new TextBlock { Text = "Not Found: " + name };
+ }
+ }
+
+ public bool Match(object data)
+ {
+ return data is ViewModelBase;
+ }
+ }
+}
\ No newline at end of file |
