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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:34:32+00:00 2026-05-26T22:34:32+00:00

I am working with MVVM and encounter the following problem with the use of

  • 0

I am working with MVVM and encounter the following problem with the use of many similar commands.

I wanna make many buttons which is used to show the books of different categories.

The model is some data about a book, say,

class book 
{
    string name;
    string author;
    .....
    .....
    string category;
}

A list of book is stored. A GUI is used for the user to view the books with different categories. Therefore, buttons for each category is created. For example:

Buttons:

Comic
Social
Academic
Science
Leisure
Political
Cartoon
Gambling
Magazine
All

There are about 10 buttons that I have to created. (9 categories, 1 for viewing all)

In MVVM, each button has its own command. From that, there would be 10 commands in the ViewModel. However, the coding 9 of its are very similar with the only difference in the category.

So, I would like to ask if there is any suggestion/methods to make it more code-saving?

I do have an idea. That is to combine all the commands into one. However, this method required the View (Xaml) to pass a CommandParameter in each button to the one command in order to distinguish the different category. This will make the XAML more complex and increase coupling level with the ViewModels/Business logic.

So, would there are more concise way?

  • 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-26T22:34:33+00:00Added an answer on May 26, 2026 at 10:34 pm

    You can use DelegateCommand from Microsoft.Practices.Composite.Presentation.dll and use CommandParameter

        <Button Command="{Binding bookCmd}"  CommandParameter="Comic">
        <Button Command="{Binding bookCmd}"  CommandParameter="Music">
        <Button Command="{Binding bookCmd}"  CommandParameter="News">
    
    
    private DelegateCommand<string> _bookCmd;
    
    _bookCmd= new DelegateCommand<string>(ExecuteBookCmd);
    
    private void ExecuteBookCmd(string category)
    {
     //Have fun
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with MVVM and wondering how to make use of ObservableCollection
I'm working on Silverlight, of course I use MVVM. I found many problems but
I'm working on a WPF application and I'm using the MVVM pattern. I use
I would like to use an MVVM in a WPF project I'm working on,
I am working with Attached Property in MVVM and encountered a interesting problem. I
I am working in wpf - mvvm model. I have a textbox which holds-
I'm used to working in WPF with the MVVM design pattern, but I've recently
I am working through an MVVM tutorial, and I have the following code, written
I am working on a MVVM wpf application and I need to show various
I am working on a WPF app using the MVVM patterm, which I am

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.