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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:28:51+00:00 2026-06-08T20:28:51+00:00

I have an application, and I have an assembly. In the application, I have

  • 0

I have an application, and I have an assembly.

In the application, I have a window, and in the assembly I have a user control.

There is an instance of the user control in the window.

Both the user control and the window are backed by separate viewmodels.

In the user control, there is a button. The button should be enabled/disabled based on the state of the user control’s viewmodel. When the button is clicked, processing needs to be done, based on the information in the user control’s viewmodel, but it needs to be done by the window’s viewmodel. (There are aspects of what needs to be done that are, and should be, outside of the scope of the user control.)

And here’s the twist – this user control won’t be used exclusively in this window, it might be used in another, or in a control that is used in a third. The user control can’t be allowed to know what kind of window or control contains it, or is handling the process when its button is clicked.

So, what to do?

Define a command in the assembly, and bind the user control’s button to it, passing the user control’s viewmodel as the command parameter? How, then, do I bind the command to the window’s viewmodel?

Or should I define the command in the user control’s viewmodel, then raise an event to tell the parent window that the appropriate action needs to be taken?

It’s not clear to me which is cleaner.

  • 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-08T20:28:53+00:00Added an answer on June 8, 2026 at 8:28 pm

    If you always know that the parent’s property is going to be exposed the same with the same name, you can do something like this that has worked for me plenty of times:

    Command={Binding Parent.DataContext.SomeCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}
    

    This gets the usercontrol, then goes to the parent and gets that datacontext and binds it to that command. This works when the user control will be encompassed by many windows / controls that expose the same command (you could implement an interface here).

    You could then pass the user control’s viewmodel to the command (again, implement some interface) like so:

    CommandParameter={Binding }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF user control defined in an application assembly. I'm trying to
I have a user control UserControl which is in an assembly Assembly. I have
I have a window in one assembly that has a TextBlock control that I
I have created the WPF user control and WPF window in class library project.
I have two libraries and a single application assembly project layout and I'm wondering
I have a ASP.NET MVC application which is build up as an assembly that
So I have this asp.net web application that I renamed. I changed the assembly
Currently I have an assembly used for a windows UI application which got a
I have an application that allows the user to change color schemes based on
I have a windows application that uses an assembly that stores some configuration settings

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.