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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:52:40+00:00 2026-05-16T00:52:40+00:00

I have 18 Buttons within a Uniform grid on my main WPF window. I

  • 0

I have 18 Buttons within a Uniform grid on my main WPF window. I need to modify many of the Button’s Properties and Command both when the program loads and during operation. In other words, when the program first starts, a configuration is selected that affects the layout. Later that could change further depending on how the program operates. I’m trying to consolidate all logic within a ViewModel. So the simple question is – how to best implement this design?

A few ideas:

  • Could use traditional bindings. This works except you could end up with 100’s of them. Also, would have ugly logic within each property – i.e. if config1 then background is red, else if config2 or 3 then background is blue.

  • Could limit the number of bindings with ValueConverters and CommandParameters but then you have even messier property logic.

  • Could bind to the Button’s style. This works to simplify the property settings but you end up with a bunch of styles to mess with. Also doesn’t work well after the program is loaded (I don’t think you can change a Style after it’s applied).

  • Could have a different Uniform grid (each with a set of 18 buttons) for each configuration, then only show the selected one. This simplifies the property logic but messes up the XAML.

  • Could pass the Button objects themselves to the ViewModel. Not sure how to implement this plus I think it breaks the MVVM pattern. Might be the easiest if I knew how to do it.

I’m at a loss for an elegant solution. I’m sure there is something simple I’m missing. Any ideas are appreciated. Thanks.

  • 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-16T00:52:41+00:00Added an answer on May 16, 2026 at 12:52 am

    Here is what I have done in that case:

    Since you have several properties you want to bind to on each button, including a command, I would make a separate, small ViewModel (MyButtonViewModel) for each button, which includes the properties and command.

    Then, in the primary ViewModel, I would create a collection (ObservableCollection<MyButtonViewModel>) of your button view models, and populate it using some simple looping (or LINQ) code.

    Then, in the View, I would declare an ItemsControl to use an ItemPanel of UniformGrid. Then, For the ItemTemplate, I’d define the button to bind to the properties in MyButtonViewModel.

    Simple, small, and elegant IMO.

    Let me know if you need any clarification,
    B

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

Sidebar

Related Questions

I have a number of buttons within a grid, that all change size based
I have a button that, when pressed, will add a new HTML row. Within
I have buttons on a page that look like: <p> <a href=view.php> <input type=button
My coworker and I constantly argue about button sizes. I like to have buttons
I have 3 buttons in a form. One of them is the submit button.
I have three buttons and need to save some data. I have a idea,
I have two buttons with the same ID: <button type=submit onclick=//do something id=theID>button 1</button>
I have buttons contained within a repeater. A ModalPopupExtender is used to confirm event
I have 2 buttons within a toolbar. Is there a way to hide the
I have several buttons positioned on my ViewController within the area covered by the

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.