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 3302952
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:54:23+00:00 2026-05-17T20:54:23+00:00

I try to rewrite my Application using the MVVM pattern. I have a window

  • 0

I try to rewrite my Application using the MVVM pattern.

I have a window to show related documents for different objects with static methods like this:

    public partial class ShowRelatedDocuments : Window
    {

    private ShowRelatedDocuments()
    {
        InitializeComponent();
    }

    public static void ShowRelatedDocument(A objA)
    {
        ShowRelatedDocuments srd = new ShowRelatedDocuments();
        srd.HandleA(objA);
        srd.ShowDialog();
    }

    public static void ShowRelatedDocument(B objB)
    {
        ShowRelatedDocuments srd = new ShowRelatedDocuments();
        srd.HandleB(objB);
        srd.ShowDialog();
    }}

Is there a way to keep these methods static like this?

ShowRelatedDocumentsVM.ShowRelatedDocument(A objA);
ShowRelatedDocumentsVM.ShowRelatedDocument(B objB);

I didn’t find anything about ViewModels and static methods. Can a VM create a instance of itself and show his View (here a window)?

Or is the better way to pass the objects as parameter to the constructor of the VM like this?

public ShowRelatedDocumentsVM(A objA)
{
  HandleA(obj A)
  ShowRelatedDocuments srd = new ShowRelatedDocuments();
  srd.DataContext = this;
  srd.ShowDialog();
}

public ShowRelatedDocumentsVM(B objB)
{
  HandleB(objB);
  ShowRelatedDocuments srd = new ShowRelatedDocuments();
  srd.DataContext = this;
  srd.ShowDialog();
}

Or are both ways wrong, cause i breach the MVVM pattern due creating the view in the viewmodel?

Thx in advance.

  • 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-17T20:54:23+00:00Added an answer on May 17, 2026 at 8:54 pm

    How to display dialogs is one of the areas of MVVM that is not immediately clear, and there are a number of ways the behaviour can be achieved.

    I would suggest using either a mediator (as described here) or by injecting a dependency on the view model that controls dialogs:

    interface IDialogService
    {
        void ShowRelatedDocumentsA(A a);
    }
    

    …

    class MyViewModel
    {
        private IDialogService _dialogService
    
        public MyViewModel(IDialogService dialogService) { _dialogService = dialogService; }
    
        public void DoSomething()
        {
            _dialogService.ShowDialog(...);
        }
    }
    

    Either of these can will permit you to control the creation of the view outside of the view model, and will remove any explicit references from VM -> V.

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

Sidebar

Related Questions

I'm using the Application Request Routing and URL Rewrite modules in IIS7.5 to host
I have a web application using the .Net 2.0 framework. The whole website is
I have web application which using spring wicket and sql-processor (similar to mybatis) which
I try to rewrite and customize @Html.ActionLink , in one of overloads of this
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
I am using jQuery ui in a rails application. I want to load content
I'am trying to rewrite zend framework configuration file from application.ini to application.yml format and
I would like to rewrite an application that currently works as a Windows GUI
I have a sitw built using codeigniter using htaccess. But on some requests are

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.