Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 863 Bytes

how-to-implement-multi-page-apps.md

File metadata and controls

39 lines (28 loc) · 863 Bytes
id title
how-to-implement-multi-page-apps
How To Implement Multi-page Apps

How To Implement Multi-page Apps

Content in preparation.

This guide will show you how to employ user controls as page views, and the view locator class, to implement a multiple-page application.

that is added by the Avalonia MVVM solution template.

public class ViewLocator : IDataTemplate
{
    public Control? Build(object? data)
    {
        if (data==null) return null;
        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;
    }
}