Files
romrepomgr/RomRepoMgr/ViewLocator.cs

29 lines
854 B
C#
Raw Normal View History

2020-08-21 22:22:24 +01:00
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using RomRepoMgr.ViewModels;
2024-11-09 01:37:59 +00:00
namespace RomRepoMgr;
2020-08-21 22:22:24 +01:00
2024-11-09 01:37:59 +00:00
public class ViewLocator : IDataTemplate
{
public bool SupportsRecycling => false;
2020-08-21 22:22:24 +01:00
2024-11-09 06:14:25 +00:00
public Control Build(object data)
2024-11-09 01:37:59 +00:00
{
string name = data.GetType().FullName?.Replace("ViewModel", "View");
Type type = name is null ? null : Type.GetType(name);
2020-08-21 22:22:24 +01:00
2024-11-09 01:37:59 +00:00
return type is null
? new TextBlock
{
Text = "Not Found: " + name
}
: (Control)Activator.CreateInstance(type);
2020-08-21 22:22:24 +01:00
}
2024-11-09 01:37:59 +00:00
public bool Match(object data) => data is ViewModelBase;
2020-08-21 22:22:24 +01:00
}