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 try to add an addons system to my Windows.Net application using Reflection; but
I have a web application using the .Net 2.0 framework. The whole website is
Should I try to actually upgrade my existing app, or just rewrite it mostly
I try to define a schema for XML documents I receive. The documents look
We try to convert from string to Byte[] using the following Java code: String
When I try to rewrite a URL in ASP.NET I'm finding that the URL
I am using jQuery ui in a rails application. I want to load content
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
try { ... } catch (SQLException sqle) { String theError = (sqle).getSQLState(); ... }
I try to fetch a Wikipedia article with Python's urllib: f = urllib.urlopen(http://en.wikipedia.org/w/index.php?title=Albert_Einstein&printable=yes) s

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.