Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 831787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:15:44+00:00 2026-05-15T04:15:44+00:00

I would like to build a generic/re-usable modal dialog that I can use in

  • 0

I would like to build a generic/re-usable modal dialog that I can use in our WPF (MVVM) – WCF LOB application.

I have a Views and associated ViewModels that I would like to display using dialogs. Bindings between Views and ViewModels are done using Type-targeted DataTemplates.

Here are some requirements that I have been able to draft:

  • I prefer this to be based on a Window instead of using Adorners and controls that act like a modal dialog.
  • It should get its minimum size from the content.
  • It should center on the owner window.
  • The window must not show the Minimize and Maximize buttons.
  • It should get its title from the content.

What is the best way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:15:44+00:00Added an answer on May 15, 2026 at 4:15 am

    I’m answering my own question to help others find all answers I struggled to find in one place. What above seems like a straight forward problem, actually presents multiple problems that I hope to answer sufficiently below.

    Here goes.

    Your WPF window that will serve as the generic dialog can look something like this:

    <Window x:Class="Example.ModalDialogView"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:ex="clr-namespace:Example"
            Title="{Binding Path=mDialogWindowTitle}" 
            ShowInTaskbar="False" 
            WindowStartupLocation="CenterOwner"
            WindowStyle="SingleBorderWindow"
            SizeToContent="WidthAndHeight"
            ex:WindowCustomizer.CanMaximize="False"
            ex:WindowCustomizer.CanMinimize="False"
            >
        <DockPanel Margin="3">
            <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" FlowDirection="RightToLeft">
                <Button Content="Cancel" IsCancel="True" Margin="3"/>
                <Button Content="OK" IsDefault="True" Margin="3" Click="Button_Click" />
            </StackPanel>
            <ContentPresenter Name="WindowContent" Content="{Binding}"/>
        </DockPanel>
    </Window>
    

    Following MVVM, the right way to show a dialog is through a mediator. To use a mediator, you typically require some service locator as well. For mediator specific details, look here.

    The solution I settled on involved implementing an IDialogService interface that is resolved through a simple static ServiceLocator. This excellent codeproject article has the details on that. Take note of this message in the article forum. This solution also solves the problem of discovering the owner window via the ViewModel instance.

    Using this interface, you can call IDialogService.ShowDialog(ownerViewModel, dialogViewModel). For now, I’m calling this from the owner ViewModel, meaning I have hard references between my ViewModels. If you use aggregated events, you will probably call this from a conductor.

    Setting the minimum size on the View that will eventually be displayed in the dialog doesn’t automatically set the minimum size of the dialog. Also, since the logical tree in the dialog contains the ViewModel, you can’t just bind to the WindowContent element’s properties. This question has an answer with my solution.

    The answer I mention above also includes code that centers the window on the owner.

    Finally, disabling the minimize and maximize buttons is something WPF can’t natively do. The most elegant solution IMHO is using this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to build a generic class that I can use to implement
I would like to build an application that uses Genetic Programming to figure out
I have a system.collections.generic.list(of ListBox) I would like to use the collection classes built-in
I would like to build a regexp in Java that would be passed in
I would like to build an application that will run on a web, this
I would like to build a query that will pull the number of rows
I would like to build a cross-platform GUI application in Python that displays PostScript
Our build has a variety of generated HTML reports. I would like to have
I would like to build a notification system that will give updates to the
I would like to build an excel VBA program to find all the match

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.