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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:19:16+00:00 2026-05-21T04:19:16+00:00

I have an ItemType that is coming from EF. This ItemType is wrapped in

  • 0

I have an ItemType that is coming from EF. This ItemType is wrapped in a ItemTypeViewModel. Many ItemTypes are wrapped in ItemTypeViewModels and are being put in a ObservableCollection in the ViewModel for the user control that will display them:

Screen2

I use the CollectionView so I can page through them. The screen looks like this:

Screen

Now I’m thinking that the buttons that are used for paging that are in the user control could better be placed in the Window that will contain the user control. So, in my user control I know have commands like this:

enter image description here

But I want them to be in the window. I don’t know if this will be good design, but if I will go through with this, how to relay the commands from the window to the usercontrol?

Another question I have is how to fill the combobox in the user control. They will always have the same values, but the selected item will change per ItemType.

  • 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-21T04:19:17+00:00Added an answer on May 21, 2026 at 4:19 am

    I know two ways how to do this.

    1) Add new class, for example, MainWindowViewModel and add there 2 commands and an instance of UserControlViewModel (you haven’t said the title, so I will call it in this way). Here is a part of example:

    public class MainWindowViewModel
    {
        public UserControlViewModel ChildControlViewModel { get; set; }
    
        private Lazy<RelayCommand> nextCommand = new Lazy<RelayCommand>(() => 
            new RelayCommand(
                () => this.ChildControlViewModel.CollectionView.MoveCurrentToNext(),
                () => this.ChildControlViewModel.CollectionView.CurrentPosition < this.ChildControlViewModel.ItemTypes.Count - 1)); 
    
        public ICommand NextCommand
        {
            get { return nextCommand.Value; }
        }
    
        //prev command...
    }
    

    I have used the Lazy class, but the main idea is clear: the code is the same, except the call this.ChildControlViewModel.CollectionView instead of CollectionView.

    2) Use the Messenger class.

    This way isn’t so obvious and it has only one advantage: the viewmodels are loosely connected.

    public class MainWindowViewModel
    {
        public const string NextCommandNotification = "NextCommand";
        public const string PreviousCommandNotification = "PreviousCommand";
        private bool isNextCommandEnabled;
        private bool isPreviousCommandEnabled;
    
        public MainWindowViewModel()
        {
            this.NextCommand = new RelayCommand(
                                    () => Messenger.Default.Send(new NotificationMessage<MainWindowViewModel>(this, NextCommandNotification)), 
                                    () => this.isNextCommandEnabled);
            //prev command...
    
            Messenger.Default.Register<NotificationMessage<UserControlViewModel>>(this,
                    msg =>
                    {
                        if (msg.Notification == UserControlViewModel.CurrentItemChangedNotification)
                        {
                            this.isNextCommandEnabled = msg.Content.CollectionView.CurrentPosition < msg.Content.ItemTypes.Count - 1;
                            this.NextCommand.RaiseCanExecuteChanged();
                            //prev command...
                        }
                    });
        }
    
        public ICommand NextCommand { get; private set; }
        //prev command...
    }
    
    public class UserControlViewModel
    {
        public const string CurrentItemChangedNotification = "CurrentItemChanged";
    
        public UserControlViewModel()
        {
            Messenger.Default.Register<NotificationMessage<MainWindowViewModel>>(this,
                    msg =>
                    {
                        if (msg.Notification == MainWindowViewModel.NextCommandNotification)
                            this.CollectionView.MoveCurrentToNext();
                        else if (msg.Notification == MainWindowViewModel.PreviousCommandNotification)
                            this.CollectionView.MoveCurrentToPrevious();
                    });
    
            this.CollectionView.CurrentChanged += (s,e) => Messenger.Default.Send(new NotificationMessage<UserControlViewModel>(this, CurrentItemChangedNotification))
        }
    }
    

    I’m not sure whether this code will work correctly. And it is not easy to explain.

    The MainWindowViewModel class send the message when a user press the button. The UserControlViewModel class process the message, change the position of the current item, and send the CurrentItemChangedNotification message. The MainWindowViewModel class process this message and updates the CanExecute part of the command.

    1st solution is better for me, but at the same time I use the Messenger class quite often. It depends on the situation.

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

Sidebar

Related Questions

I have a templated container class that looks something like this: template <class ItemType>
I have a OdbcDataReader that gets data from a database and returns a set
I have a model that looks like this: Ext.regModel('TreeItem', { fields: [ { name:
I have this code: function Item(id, itemType, itemData, itemCategoryId, itemRank) { this.id = id;
I have a listview that loads dynamic controls from xml/xslt <asp:ListView ID=DynamicFields runat=server DataSourceID=CustomFields
I have a View with a form which displays data from objects that are
I have created a class that inherits from RadioButtonList in order to add a
I have code like this protected void rptCategory_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType
I have this JSP code snippet: <%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=c%> <c:choose> <c:when test=${var1.properties[\Item Type\]
I have a nested list like this: <ul class=list> <li class=list_item_type_1> <ul class=list> <li

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.