App-UI navigation with uxml based screens

I want to use the navigation graph from App-UI.

In all the examples, the navigation screens are put together in code. I would like to use uxml visual tree asset instead. Does anyone know what is the right to use uxml with the navigation tools?

Ideally, I would put properties on the NavigationScreen or add a parameter in the constructor and set them in the graph editor. I would just have a VisualAssetTree as the parameter and clone the tree inside the constructor.

1 Like

Hello!

The current navigation system expects classes derived from NavigationScreen in order to be displayed in the graph. So ultimately you will need to create some code for that.
Your suggestion looks correct, you can always create templates in UXML and clone them during construction of the navigation screen.

That being said, i am wondering if you have any ui logic to do on the C# side? How are you gonna bind ui controls to your business logic? Were you planning on sharing a common NavigationScreen class type or creating a different class type per UXML template? Because if its the second case, having visualtree asset fields in the graph wont be that useful.

You are not the first person asking about customizing the node content in navigation graph. That something we can investigate. We had some ideas about removing the NavigationScreen class completely so user could use any kind of element instead. But it has been deprioritized. We may be able to bring it back soon, but i cant provide a precise date.

1 Like

I see.

Each screen needs some C# logic to bind to events and whatnot. I suppose I can do Resources.Load and clone the uxml tree in the constructor until there is a better way.

I look forward to see what you guys come up with.

Maybe just an inspiration how a base class for such views could look like, which:

  • Loads a UXML template (that also contains the bindings to the data context / view model)
  • Resolves the corresponding view model from your IoC to set it as data context

The concrete views are then just empty subclasses that define the view model type.

@mickael-bonfill So to answer your question, in our case, we use the runtime binding engine and do not need any C# “code-behind” in our views. There are maybe some exceptions, but mostly because the runtime binding in UI Toolkit is of course not as mature as what other frameworks like WPF offer.

    public class ViewBase<TViewModel> : NavigationScreen
    {
        public ViewBase()
        {
            var viewName = GetType().Name;
            var visualTree = Resources.Load<VisualTreeAsset>(viewName);

            if (visualTree == null)
            {
                throw new Exception($"{viewName} not found.");
            }

            visualTree.CloneTree(this);

            dataSource = Ioc.Default.GetRequiredService<TViewModel>();
        }
    }
1 Like

Can you? I add properties to the navigation screen and they don’t show in the graph editor. Am I missing something?

Besides, properties do not get set until after the constructor is invoked no?