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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:48:34+00:00 2026-06-11T03:48:34+00:00

I have a user control ‘A’ that has another user control ‘B’ as its

  • 0

I have a user control ‘A’ that has another user control ‘B’ as its child. The usecase scenario being, when the user clicks a button on ‘A’, it should request ‘B’ to process some information (typically relating to the state of ‘B’) and get the result, which will then be used in some calculation in ‘A’.

Now, I am using MVVM pattern. The viewmodel of ‘A’ does not have any reference to either the UI of A or B. I am exactly looking for this: When a user cliks a button on the UI of ‘A’, I need to call a command in ‘B’, by passing a delegate in the viewmodel of ‘A’ as a parameter to that command. This way, when the command in ‘B’ processes information, it can then call the callback function passed from ‘A’.

Now, the delegate is parameter-less. Once the command in usercontrol ‘B’ processes some information, it updates its state. This state is a dependency property which will be binded to a property in the viewmodel of ‘A’.

Is there a way to achieve something like this?

I have a working solution currently. But I want to improvise the code and make it better. This is my current temporary workaround to this problem:

When the user clicks a button in ‘A’, I am having an Event Handler in ‘A’ (xaml.cs). In the event handler, as I have the reference of ‘B’, I am checking if the command in ‘B’ can be executed, and then call it. Then, I check if command (in viewmodel of ‘A’) can be executed, and then call it.

If my question was not descriptive enough, here is a code sample to support it:

XAML of ‘A’:

<bNameSpace:B x:Name="BObject" DepenPropertyInB="{Binding PropInA, Mode=OneWayToSource}"/>
....
<telerik:RadButton Content="Process" HorizontalAlignment="Right" Height="30" Width="80" Grid.Column="2" Click="ProcessButton_Click" />

XAML.cs of A:

private void ProcessButton_Click(object sender, RoutedEventArgs e)
{
    if (BObject.StateDataRequestedCommand.CanExecute(""))
        BObject.StateDataRequestedCommand.Execute("");

    if(ViewModel.ProcessInfoRequestedCommand.CanExecute(""))
        ViewModel.ProcessInfoRequestedCommand.Execute("");
}

ViewModel of A:

private void OnProcessInfoRequestedCommand(string anyValue)
{
    // read the value of PropInA and do some processing
}

ViewModel of B:

private void OnStateDataRequestedCommand(string anyValue)
{
    // Bases on B's state do some calc and update DepenPropertyInB
}
  • 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-11T03:48:36+00:00Added an answer on June 11, 2026 at 3:48 am

    I’ll come back and add more detail to this later, but here’s basically what I think needs to happen.

    The click should have a DelegateCommand type implementation, that contains a reference to the view models of both A and B. You need some kind of “conductor” class that is instantiating the view models, and which can pass the appropriate references into the command object.


    So, clearly the command belongs in the View Model for A, but, it needs a reference to B. So set up the command class with that in mind:

    public MyCommand : ICommand
    {
        private readonly ViewModelA _a, ViewModelB _b;
    
        public MyCommand(ViewModelA a, ViewModelB b)
        {
            _a = a;
            _b = b;
        }
    
        public bool CanExecute(object arg)
        {
            // can-execute logic here
        }
    
        public void Execute(object arg)
        {
            _b.StateDataRequestedCommand.Execute("");
            _a.ProcessInfoRequestedCommand.Execute("");
        }
    }
    

    Now, but an instance of MyCommand into A’s View Model…

    public MyCommand StateRequestedCommand { get; set; }
    

    And bind to it as normal…

    <telerik:RadButton Command="{Binding StateRequestedCommand}" />
    

    Now, the challenge is to instantiate this class within A’s View Model somehow. I normally use NInject to inject external dependencies into classes, but there are different ways to do it. Either way, it has to happen at a higher level than ViewModelA itself, since it doesn’t have a reference to ViewModelB. That could be in the App_Startup logic, or in IoC (eg, NInject) bindings, or in a View Model “Locator”, if that’s what you’re using.

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

Sidebar

Related Questions

I have an User Control that host another controls like panel, chart controls. Right
I have a user control that is being integrated to the page on run
I have web user control A that uses another web user control B. Inside
I have a user control on a form that can spawn several non-modal child
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have a user control that has a public property defined in the code-behind
I have a User Control displaying some data and a button that displays a
I have a user control named Navigation that has a property that holds navigation
I have a user control called DashboardUserControl.ascx It has a function: public void setPagination(Boolean
I have user control under Sitecore CMS. It has some controls bound to some

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.