Avalonia.Samples icon indicating copy to clipboard operation
Avalonia.Samples copied to clipboard

Add MsExtensionsHostingSample sample project

Open maxkatz6 opened this issue 2 years ago • 10 comments

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:

  • [ ] fix or update to an existing sample
  • [x] add a new sample

Checklist

If this is a new Sample

  • [x] Added a ReadMe-file
  • [x] Updated the landing page
  • [ ] ~Consider submitting a PR to https://github.com/AvaloniaUI/Documentation with a link to your sample in the related documentation page~

In any case

  • [ ] Spell-checking done
  • [ ] Checked if all hyperlinks work
  • [ ] Checked if all images are visible

Fixed issues

Fixes #35

maxkatz6 avatar Nov 03 '23 09:11 maxkatz6

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.

pjmagee avatar Dec 18 '23 16:12 pjmagee

@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)

timunie avatar Dec 19 '23 07:12 timunie

ahh, thank you. Checking out now

pjmagee avatar Dec 19 '23 10:12 pjmagee

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?

jedidja avatar Jan 02 '24 17:01 jedidja

Why is the GlobalHost a public property here? I always keep the host private, in order to guard it from outside access. You should not need it anywhere else in your code, because you use DI anyway, or am I missing details?

mrmorrandir avatar Sep 29 '24 09:09 mrmorrandir

Why is the GlobalHost a public property here? I always keep the host private, in order to guard it from outside access. You should not need it anywhere else in your code, because you use DI anyway, or am I missing details?

DesignData class is using it.

pjmagee avatar Sep 29 '24 09:09 pjmagee

Ahhh thanks for the help, I totally overlooked that...

I don't like the dependency though, but I get it for this scenario.

mrmorrandir avatar Sep 29 '24 14:09 mrmorrandir

Ahhh thanks for the help, I totally overlooked that...

I don't like the dependency though, but I get it for this scenario.

Might be able to make it private and expose an alternative for the DesignTime and wrap it around some compiler labels so its 'removed' from what would be considered actual runtime code?

pjmagee avatar Sep 29 '24 14:09 pjmagee