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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:17:48+00:00 2026-05-24T16:17:48+00:00

Im new to MVVM and have small problem. I have two user controls: parent

  • 0

Im new to MVVM and have small problem. I have two user controls: parent and child(with view, viewmodel, model classes). And need to pass some properties from parent to child. For now ive managed it by writing such code:

public static readonly DependencyProperty CallbackActionProperty =
                DependencyProperty.Register("CallbackAction", typeof (Action), 
        typeof (ChildView), new PropertyMetadata(default(Action)));

public Action CallbackAction
{
  get { return (Action) GetValue(CallbackActionProperty); }
  set
  {
    SetValue(CallbackActionProperty, value);
    ((ChildViewModel)this.DataContext).CallbackAction = value; // Change ViewModel property too
  }
}

This is dependency property in ChildView and on its set i also set its ViewModel‘s property. After that i access that dependency property from ParentView and set the CallbackAction-> that sets the CallbackAction in Child’s ViewModel.
Code:

  this.Loaded += (sender, args) => childUc.CallbackAction = ((ParentViewModel) this.DataContext).RefreshStatuses;

childUc is usercontrol, located on parent and represented by ChildView.
Code is ugly, so i hope to see better practice in terms of not breaking pattern.
Thank you.

  • 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-24T16:17:49+00:00Added an answer on May 24, 2026 at 4:17 pm

    Yep – this code is pretty ugly. In fact I am struggling to work out exactly what it does!

    One of the main tenants of the MVVM pattern is that the ViewModel should be unit testable and it should be possible to execute it without the view. When faced with this kind of problem, think about the view Model alone and ignore the view.

    Your ParentViewModel has a reference to the ChildViewModel, you can make this a two way relationship by having the ParentViewModel provide a reference to itself when you create the ChildViewModel. This means that from the ChildViewModel you can execute any public method on the ParentViewModel.

    With this in mind, you should be able to solve your problem!

    (Also, you should not add logic in your dependency property getter or setter, this code may or may not be called depending on how your dependency property value is set.)

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

Sidebar

Related Questions

I am fairly new to MVVM, so bear with. I have a view model
I'm new to MVVM. I have a label in my view that looks like
Being a new to WPF/XAML/MVVM, I've got a question. In my View, I have
I am new to MVVM and have written a small app to test the
I have a user control called HomePage.xaml . I'm creating a model instance (using
I am new to the MVVM model, so I would like some advice, the
I'm fairly new to MVVM, and I have recently started a project cleaning up
I have a problem updating the layout of my listbox using MVVM with Prism
I have a little problem with MVVM. Let me first sketch my problem. I
I need to figure out how to communicate between ViewModels. I'm new to MVVM

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.