AvaloniaUtils / DialogHost.Avalonia

AvaloniaUI control that provides a simple way to display a dialog with information or prompt the user when information is needed
MIT License
270 stars 16 forks source link

How can I have multiple different modal dialogs on the same view? #74

Closed amp64 closed 2 days ago

amp64 commented 4 days ago

I need different modal dialogs at different times, each triggered by a different bool, how can I do that in XAML?

I have been trying to use multiple views in the same DialogContent (see source) but any more than three and Avalon crashes with "Invalid Arrange rectangle" (on Android, Windows is fine). Is there a better way?

SKProCH commented 3 days ago

Hello, @amp64

If you need all this completely without C# code - this is seems like the only solution. But if you can use C# code, you can pass different views or different viewmodels (with different DataTemplates for each model type) to DialogHost.Open.

crashes on Android, Windows is fine

This sounds like an Avalonia/your views bug. If you add

<Grid>
<views:GroupVolumeView DataContext="{Binding CurrentZone}" IsVisible="{Binding $parent[dialogHostAvalonia:DialogHost].((vm:MainViewModel)DataContext).VolumePopupOpen, Mode=TwoWay}"/>
<views:GroupEditorView DataContext="{Binding CurrentZone}" IsVisible="{Binding $parent[dialogHostAvalonia:DialogHost].((vm:MainViewModel)DataContext).GroupEditorOpen, Mode=TwoWay}"/>
<views:QueueView DataContext="{Binding CurrentZone}" IsVisible="{Binding $parent[dialogHostAvalonia:DialogHost].((vm:MainViewModel)DataContext).QueuePopupOpen, Mode=TwoWay}"/>
</Grid>

as part of your usercontrol without DialogHost (so basically remove the DialogHost) will the problem still persist?

amp64 commented 3 days ago


as part of your usercontrol without DialogHost (so basically remove the DialogHost) will the problem still persist?

I removed all DialogHost stuff and added the two new Views in there and it does not crash on Android. The "invalid arrange rectangle" only repros when wrapped with DialogHost.

I am now trying your suggestion about passing different views to DialogHost.Open instead of doing this in XAML. Thanks.

SKProCH commented 3 days ago

Can you try to extract this grid and views into a separate minimal reproduceable project for easier debugging from my side?

DialogHost shouldn't cause arrange issues of course, seems like this is a bug.

amp64 commented 3 days ago

I removed the XAML and used DialogHost.OpenDialogCommand.Execute(view) instead and it is working fine now. Not sure I can produce a simple project repro but if you like I can give you the 4 lines to add to my XAML to repro it in my full project. (You don't need a Sonos device to repro the issue)

SKProCH commented 2 days ago

Yeah, I can try to debug it.

amp64 commented 2 days ago

After re-working everything to avoid the XAML stuff, I ended up with the exact same "invalid arrange rectangle" although with a clearer callstack. Turns out my main View was not fully formed (there is some async stuff) before I was trying to Open a modal dialog in it. I don't have a real fix yet, but adding a Task.Delay(1000) has unblocked me, and I think when I figure it all out I can restore my original XAML.

TL;DR no bug to see here except in my own code.

SKProCH commented 1 day ago

Hope you can fix it!

amp64 commented 1 day ago

Fix turned out to be easy: wait until OnLoaded is called on the View, and THEN Init Async the viewmodel: I was doing the async init from the viewmodel constructor, which was a bad idea.