feat: initialize, setup demo. make sure MVVM works.
This commit is contained in:
29
demo/Ursa.Demo/DataTemplates/ViewLocator.cs
Normal file
29
demo/Ursa.Demo/DataTemplates/ViewLocator.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Ursa.Demo.Pages;
|
||||
|
||||
namespace Ursa.Demo.Converters;
|
||||
|
||||
public class ViewLocator: IDataTemplate
|
||||
{
|
||||
public Control? Build(object? param)
|
||||
{
|
||||
if (param is null) return null;
|
||||
var name = param.GetType().Name!.Replace("ViewModel", "");
|
||||
var type = Type.GetType("Ursa.Demo.Pages."+name);
|
||||
if (type != null)
|
||||
{
|
||||
return (Control)Activator.CreateInstance(type)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TextBlock { Text = "Not Found: " + name };
|
||||
}
|
||||
}
|
||||
|
||||
public bool Match(object? data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user