Cross Platform Application to allow control with a MIDI controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
759 B

// Author: Gockner, Simon
// Created: 2021-04-06
// Copyright(c) 2021 SimonG. All Rights Reserved.
using System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Mystify.ViewModels;
namespace Mystify
{
public class ViewLocator : IDataTemplate
{
public bool SupportsRecycling => false;
public IControl Build(object data)
{
string name = data.GetType().FullName!.Replace("ViewModel", "View");
Type? type = Type.GetType(name);
if (type != null)
return (Control) Activator.CreateInstance(type)!;
return new TextBlock { Text = "Not Found: " + name };
}
public bool Match(object data) => data is ViewModelBase;
}
}