semesterWork/Presence.Desktop/ViewLocator.cs

31 lines
722 B
C#
Raw Normal View History

2024-12-07 13:38:28 +00:00
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Presence.Desktop.ViewModels;
using System;
2024-12-08 15:00:30 +00:00
using Presence.Desktop.Views;
using ReactiveUI;
2024-12-07 13:38:28 +00:00
namespace Presence.Desktop
{
2024-12-12 18:16:01 +00:00
public class ViewLocator : IDataTemplate
2024-12-07 13:38:28 +00:00
{
2024-12-12 18:16:01 +00:00
public Control Build(object data)
2024-12-07 13:38:28 +00:00
{
2024-12-12 18:16:01 +00:00
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;
}
2024-12-07 13:38:28 +00:00
}
}