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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:46:10+00:00 2026-06-08T06:46:10+00:00

I have two ViewModels in my MVVM app. the one is bind to main

  • 0

I have two ViewModels in my MVVM app. the one is bind to main window and another to popup window which appears after click on the button. in the popup window I need binding to the selected entity from main window. how can I access this entity in MainViewModel from PopupViewModel?

  • 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-08T06:46:13+00:00Added an answer on June 8, 2026 at 6:46 am

    ZK has the concept of the event queue and global commands for communication between multiple ViewModels so we can use that to pass the current selected entity to the ViewModel of a popup window.

    Using this zk mvvm demo page:

    (see docs)

    I added to the listbox a global command which fires out the current selected reminder of the main ViewModel which needs to be shown by a popup window:

        <listbox id="list" multiple="true" rows="6"
            model="@load(vm.reminders)"
            selectedItem="@bind(vm.selectedReminder)" 
            onSelect="@global-command('refresh', reminder=vm.selectedReminder)">
    

    Then I added to the bottom of the page a popup window with a second ViewModel:

        <window id="info" visible="false" width="120px" border="normal" position="parent"
         apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('org.zkforge.zktodo2.ui.ViewModelPopup')"
        >
    You have selected <label value="@load(vm.currentReminder.name)"/>
    </window>
    <button label="More info" onClick="info.doPopup()"/>
    </zk>
    

    The pop up Viewmodel has a method which accepts the global command which takes the entity as a parameter:

    public class ViewModelPopup  {
    
        protected Reminder currentReminder = new Reminder();
    
        public Reminder getCurrentReminder() {
            return currentReminder;
        }
    
        public void setCurrentReminder(Reminder currentReminder) {
            this.currentReminder = currentReminder;
        }
    
        @GlobalCommand @NotifyChange("currentReminder")
        public void refresh(@BindingParam("reminder") Reminder reminder ){
            this.setCurrentReminder(reminder);
            return;
        }
    
    }
    

    So now whenever you select an item in the listbox the refresh method is fired on the popup ViewModel passing into it data taken from the main ViewModel. Whenever you hit the “More info” button at the bottom of the page to show the popup window it displays the name of the current selected entity.

    The documentation which I followed to do this is at:

    (docs1)

    (docs2)

    The instructions to run that sample app are on the readme at (Docs3)

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

Sidebar

Related Questions

I have two classes (MVC view model) which inherits from one abstract base class.
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two columns say Main and Sub . (they can be of same
in my MVVM application (in wpf) i have two view and I want to
Using MVVM Light, I have two WPF applications that reference a common Views library.
I currently have a fairly straight forward app, my first attempt at MVVM using
I have two separate views each containing a ScrollViewer. I want to slave one
I have a simple form with two fields and an optional field which is
I have wholly adopted the MVVM pattern for our silverlight app. However, some of
I am using MVVM Light. I have created a window that looks like this:

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.