Search code examples
wpfvb.netmvvmdevexpressdevexpress-windows-ui

Show View as a dialog box


I used devexpress hybrid wpf scaffolding wizard to generate a full MVVM

application with views for collections and single object views.

Now I'm struggling to figure out how to make some of the single object views popup when double clicked from the collection view, as a metroUI dialog and not like a frame with a back button.


Solution

  • I suggest you use the IDialogSerivice and it's WinUIDialogService implementation to accomplish this task. Since you are using scaffolding, you should go into your collection view (YouEntityCollectionView.xaml) and go into Behaviors section:

    <dxmvvm:Interaction.Behaviors>
        <dxwui:WinUIMessageBoxService/>
        <dxmvvm:EventToCommand Command="{Binding OnLoadedCommand}" />
        <WindowedDocumentUIService YieldToParent="True"/>
    </dxmvvm:Interaction.Behaviors>
    

    Then add your service into this section:

    <dxmvvm:Interaction.Behaviors>
        <dxwui:WinUIMessageBoxService/>
        <dxmvvm:EventToCommand Command="{Binding OnLoadedCommand}" />
        <dxwui:WinUIDialogService />
    </dxmvvm:Interaction.Behaviors>
    

    After that you should replace the IDocumentManagerService with IDialogService within the CollectionViewModel code. It may look as follows:

    // Edit:
    //DocumentManagerService.ShowExistingEntityDocument<TEntity, TPrimaryKey>(this, primaryKey);
    this.GetService<IDialogService>().ShowDialog(MessageButton.OKCancel, null, typeof(TEntity).Name + "View", primaryKey, this);
    
    // New:
    //DocumentManagerService.ShowNewEntityDocument(this, newEntityInitializer);
    this.GetService<IDialogService>().ShowDialog(MessageButton.OKCancel, null, typeof(TEntity).Name + "View", newEntityInitializer, this);