presence_sample_v2/Presence.Desktop/ViewLocator.cs

20 lines
631 B
C#
Raw Normal View History

2024-11-22 12:18:04 +00:00
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Presence.Desktop.ViewModels;
using System;
2024-12-04 08:11:13 +00:00
using Presence.Desktop.Views;
using ReactiveUI;
2024-11-22 12:18:04 +00:00
namespace Presence.Desktop
{
2024-12-04 08:11:13 +00:00
public class ViewLocator : IViewLocator
2024-11-22 12:18:04 +00:00
{
2024-12-04 08:11:13 +00:00
public IViewFor? ResolveView<T>(T? viewModel, string? contract = null) => viewModel switch
2024-11-22 12:18:04 +00:00
{
2024-12-04 08:11:13 +00:00
GroupViewModel groupViewModel => new GroupView{DataContext = groupViewModel},
PresenceViewModel presenceViewModel => new PresenceView{DataContext = presenceViewModel},
_ => throw new ArgumentOutOfRangeException(nameof(viewModel))
};
2024-11-22 12:18:04 +00:00
}
}