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

  • Home
  • SEARCH
  • 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 9194629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:27:33+00:00 2026-06-17T21:27:33+00:00

In MEFedMVVM viewmodels are instantiated using ViewModelLocator . MEFedMVVM is really powerful, since you

  • 0

In MEFedMVVM viewmodels are instantiated using ViewModelLocator. MEFedMVVM is really powerful, since you can have an arbitrary constructor for your viewmodels:

[ExportViewModel("MyViewModel")]
public class MyViewModel : NotifyPropertyChangedBase
{
    [ImportingConstructor]
    public MyViewModel(IMediator mediator, IContainerStatus containerStatus, IDispatcherService dispatcherService)
    {
    }    
}

IMediator, IContainerStatus and IDispatcherService are service interfaces which are instantiated through MEF. Obviously, I can create my own services if needed.

The problem

When my view has loaded it needs to assign a member of one of its children’s readonly property with data from the viewmodel. Ideally, I would bind this variable directly in XAML, but I cannot do that since the property is readonly and its member is not an attachable property. Currently, I have an ugly workaround:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    var viewModel = DataContext as MyViewModel;
    this.child.SomeReadonlyProperty.Data = viewModel.MyData;
}

I want to get rid of this coupling of the view and the viewmodel. Both MEFedMVVM and Prism provide different patterns that might be helpful, but I have no idea which to use – and how. Is it ok to let services have access to both the view and the viewmodel?

Q: What pattern should I use to remove the coupling?

  • 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-06-17T21:27:34+00:00Added an answer on June 17, 2026 at 9:27 pm

    I think I would be inclined to create an interface which your view can implement that will describe the behavior you need to set the property:

    interface IMyView
    {
        void SetReadOnlyProperty(object value);
    }
    

    You can then create your implementation of SetReadOnlyProperty in the view, export the view as type IMyView and finally, create an import on your viewmodel of type IMyView which will expose your method and allow you to perform calls from the viewmodel. I believe this doesn’t go against the ethos of MVVM because the viewmodel isn’t aware of the view, it just has an interface that will expose what you need.

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

Sidebar

Related Questions

In my Application i have a MainWindow that import over MEFedMVVM the ViewModel: xmlns:mefed=clr-namespace:MEFedMVVM.ViewModelLocator;assembly=MEFedMVVM.WPF
I have multiple instances of a viewmodel: <views:MyView x:Name=view1 mefed:ViewModelLocator.NonSharedViewModel=MyViewModel /> <views:MyView x:Name=view2 mefed:ViewModelLocator.NonSharedViewModel=MyViewModel
I am writing a WPF application using MEF and a third-party library called MEFedMVVM
It is about this (Inject the dependency) private readonly ICustomerService _customerService; public Billing(ICustomerService customerService)
I've been trying to figure this for a few days now, with no luck.

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.