'How can I create hierarchical menu items in a NavigationView in code behind?

I am a beginner and I am working with WPF via XAML Islands. I would like to create a hierarchical NavigationView. In the XAML Controls Library only the way via XAML is shown. Has anyone already done this?

Hierarchical NavigationView



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source