简体   繁体   中英

MVVM Dialogs and where to call them from?

Hoping that someone can help me further my understanding of Dialogs and how to apply them to the App I am working on (for learning purposes). Apologies in advance - I do not have a great working knowledge of a lot of these different technologies

The basic layout of my viewmodel structure is as in the Pic below (with corresponding Views(UserControls) ViewModel Layout

In the GroupView Model each tab is set to a Food Group for the Restaurant and the items loaded at runtime

 <ItemsControl Margin="10" ItemsSource="{Binding Plus}" >
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal" MaxWidth="410" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Button Margin="5" Width="80" Height="40"
                                Command="{Binding DataContext.AddPluCommand, RelativeSource={RelativeSource AncestorType=core:UserControlViewBase}}" CommandParameter="{Binding}">
                            <TextBlock Text="{Binding PluContent}" TextWrapping="Wrap" />
                        </Button>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>

On the Button click (via the Command : AddPluCommand) I would Like to trigger a Prep Instruction Dialog (or modal View)

Example:

On Pressing Coffee - Prep Instructions would load view with 3 buttons:

  • Hot Milk
  • Cold Milk
  • Black

All Attempts so far have yielded no results (Interaction Triggers, Dialog Service, Overlay Modal Views). The most likely reason is that I am placing the code in the wrong ViewModels (at least I think that's the reason).

Questions:

Is it possible to load a Dialog with its own ViewModel (as described above). Only Samples I have seen deal with very simple text type messages?

Which Viewmodel should be Calling the Dialog?

Thanks in advance

I found very difficult to build modal Dialog with WPF. Now I use the Mahapps Metro SimpleChildWindows, you can download it with Nugets.

This way you can build a custom modal view with its own ViewModel (if you want). Look at my question (and my answer) => SimpleChildWindows binded to View Model

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM