AvaloniaUI / Avalonia.Samples

Avalonia.Samples aims to provide some minimal samples focusing on a particular issue at a time. This should help getting new users started.
https://www.avaloniaui.net
606 stars 103 forks source link

Add MsExtensionsHostingSample sample project #64

Open maxkatz6 opened 10 months ago

maxkatz6 commented 10 months ago

What does the pull request do?

Adds a sample project on how to use .NET Generic Host in a typical Avalonia app.

Scope of this PR:

Checklist

If this is a new Sample

In any case

Fixed issues

Fixes #35

pjmagee commented 9 months ago

I have been using this branch as a basis for my IHost usage but struggled when it came to multi views using the MainWindowViewModel which needs to change the Views its currently presenting on the main window, since its 1 window, multi pages (buttons go to different views - I have one main view, but a settings view) - I only want the 1 window.

I came across some issues understanding how that works with the ViewLocator and the DI registration of MainWindowViewModel only being bound to one View.

Not sure if something would need to change a bit with the DI to make a foundation for Windows extensions generic host with a "starting example" for navigation.

timunie commented 9 months ago

@pjmagee typically you would have two ViewModels for two views where each VM is represented by a DataTemplate. Then if you swap DataContext of your Window, you should be navigated automatically. Check also the NavigationSample (okay it's without DI but concept should be similar)

pjmagee commented 9 months ago

ahh, thank you. Checking out now

jedidja commented 8 months ago

Wow what awesome timing for this PR! I just started looking into Avalonia and this was my first question :) Thanks for working on this. @maxkatz6 apart from the "in any case" items, is there anything you consider missing from the sample?