mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Initial commit
This commit is contained in:
28
KfChatDotNetGui/ViewLocator.cs
Normal file
28
KfChatDotNetGui/ViewLocator.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using KfChatDotNetGui.ViewModels;
|
||||
|
||||
namespace KfChatDotNetGui
|
||||
{
|
||||
public class ViewLocator : IDataTemplate
|
||||
{
|
||||
public Control Build(object data)
|
||||
{
|
||||
var name = data.GetType().FullName!.Replace("ViewModel", "View");
|
||||
var type = Type.GetType(name);
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
return (Control) Activator.CreateInstance(type)!;
|
||||
}
|
||||
|
||||
return new TextBlock {Text = "Not Found: " + name};
|
||||
}
|
||||
|
||||
public bool Match(object data)
|
||||
{
|
||||
return data is ViewModelBase;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user