forked from amkovkov/GranuSightSoftware2
feat: GSS2.Test - UI+DI, Vulkan render test
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
|
||||
namespace GSS2.Test;
|
||||
|
||||
public class DependencyInjectionViewLocator : IDataTemplate
|
||||
{
|
||||
public Control? Build(object? data)
|
||||
{
|
||||
if (data is null)
|
||||
return null;
|
||||
|
||||
var name = data.GetType().FullName?.Replace("ViewModel", "View");
|
||||
if (name is null)
|
||||
return new TextBlock { Text = $"Not found: {data}" };
|
||||
var type = Type.GetType(name);
|
||||
if (type is null)
|
||||
return new TextBlock { Text = $"Not found type: {name} for {data}" };
|
||||
|
||||
var control = Program.ApplicationHost.Services.GetRequiredService(type) as Control;
|
||||
if (control is null)
|
||||
return new TextBlock { Text = $"Not found in DI: {type} for {data}" };
|
||||
|
||||
control.DataContext = data;
|
||||
return control;
|
||||
}
|
||||
|
||||
public bool Match(object? data) => data is ViewModelBase;
|
||||
}
|
||||
Reference in New Issue
Block a user