Replies: 2 comments 2 replies
-
As I said in another issue, I know very little about DI and how it works, and I also don't do the pure MVVM no code behind thing (just personal preference). However, I can try to help here... Both controls were ported from WinUI. Anyway, I think this is kind of what you're going for, but again pure MVVM and DI isn't my specialty. Also this code hasn't been tested, I just wrote it out real quick. This assumes the list of 'view models' fed to the NavigationView are the same view models that are used to create views - you can of course split them up. public class MainWindowViewModel
{
public MainWindowViewModel
{
// Create page view models here - can be normal view models or you could use straight NavigationViewItems
}
public List<PageViewModel> Pages { get; }
public PageViewModel CurrentPage { get; set; } // Wire up with INotifyPropertyChanged
} In MainWindow... <NavigationView MenuItems="{Binding Pages}" Content="{Binding CurrentPage}">
<!--
Creates a NavViewItem from `PageViewModel`
See sample app page for NavView binding
-->
<NavigationView.MenuItemTemplate>
<DataTemplate>
<NavigationViewItem />
</DataTemplate>
</NavigationView.MenuItemTemplate>
<NavigationView.DataTemplates>
<!-- Define your DataTemplates here, could also use ContentTemplate if only 1 template is needed -->
</NavigationView.DataTemplates>
</NavigationView> |
Beta Was this translation helpful? Give feedback.
-
Excelent answer, simple and concise. Yes, you are right I don´t need back/forward in my app. I will test using your recomendations, but I think it will work. For now I don´t plan to use animations during Page switch, but the 'TransitioningContentControl' is a good tip. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Not a bug, just a technical question. First I'm not an expert in WPF and this is my first project using Avalonia. I'm trying to build a desktop app (windows only for now) using AvaloniaUI project and yours. I´m not using ReactiveUI, but can consider using if it make things simpler (I do reactive apps but use ReactiveProperty project instead). The question is about the use Frame and NavigationView. The use I see in the sample app is for navigation using Pages (Views). It is possible to use this two controls but with ViewModels and the View generated using DataTemplate.
Desktop/Platform (please complete the following information):
Additional context
A detail, I will try to use
Microsoft.Extensions.DependencyInjection
in the app (this is required). The ViewModels, contains several classes injected by constructor.The
MainWindowViewModel
should contain aList<NavigationViewItem>
property or similar with the menu items. The thing is I don´t know how to wire your controls implentations with my code (use ViewModels instead of Views).Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions