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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:31:25+00:00 2026-05-12T10:31:25+00:00

I thought I’d post here in the hope that maybe someone with MVVM expertise

  • 0

I thought I’d post here in the hope that maybe someone with MVVM expertise would be able to offer opinions on whether the following is a good idea:

I’m using Sacha Barber’s Cinch MVVM framework, which includes Marlon Grech’s SimpleCommand class.

One thing this class doesn’t have which some other alternatives have is a Text property, which can be commonly used to bind UI elements to the ‘Title’ of the command operation. Consequently I’ve been writing an extension to this class which exposes a Text property.

Now, what I’ve run into is a use case where I’m using a command to toggle connectivity to a device. There’s a bunch of different ways I could implement this (aren’t there always – it’s software!). One way would be to expose multiple command objects from my ViewModel – one for ‘Disconnect’ and one for ‘Connect; have the view model expose a property which indicates the connection state (IsConnected) and have the view conditionally bind to either the Connect command or Disconnect command. My reaction to this option though, is … yuck!

What I initially started looking at instead was not only providing a Text property but also having the command object implement INotifyPropertyChanged so that the text property can be dynamically altered by the viewmodel to ‘Connect’ or ‘Disconnect’ according to system state. Doing this, I can avoid having multiple commands and just expose a single ‘ToggleConnection’ command object.

Starting down this path though, it occurs to me that there may be other variations of this pattern whereby the UI needs to be altered according to command state. For example, in addition to changing the command’s text according to connection state, you may have places where an icon needs to change according to connection state. So, I started writing a ‘Stateful’ class which implements INotifyPropertyChanged, and exposes two properties – ‘Text’ and ‘State’. I’ve made the class generic so that the type of State can be defined by the user (I usually prefer not to use ‘object’ where avoidable).

The question I have is… Do you think this is a good or bad idea? It may be diverging from the original intention / design of commands; From what I’ve seen it may in general be the case that command objects were intended to be stateless as they are the ‘verbs’ of the system. With routed commands, if I understand things correctly only the target of the command would usually be expected to have state. Particularly since the same command could be routed to different handlers depending on where command bindings are declared.

So, I’m thinking that at least with routed commands, state would not make sense.

However, I’m not dealing with routed commands – I’m specifically dealing with MVVM commands. In this case there basically is no conditional routing of commands – the MVVM views bind directly to a particular viewmodel’s command objects and it’s execute and canexecute handlers.

In this case, does it make sense?

I’ve attached a copy of the code in question, in case it’s of use/interest.

Thanks,
Phil

  • 1 1 Answer
  • 1 View
  • 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-12T10:31:26+00:00Added an answer on May 12, 2026 at 10:31 am

    It’s really up to you what you think would be easier to work with.

    I personally do not put the .Text property on my commands simply because I get no reuse out of these commands. It’s different with the RoutedUICommands provided in the framework (or similar custom static commands) because they are reused everywhere and if the translation of “Exit” were to change on that command, it would be reflected throughout the application. This is not the case in your example – everything would be one-off.

    In your case this text of your button text is really decoupled from your command (even though one affects the other) and so it’s probably going to end up being easier and a little less code to decouple them, but the difference isn’t going to be that much and it will end up being a matter of taste more than anything.

    I’m definitely with you on the 2 commands thing – blech. Most button delegates you write will have to react to state in some way (service you talk to is down, this data needs to be populated this way if the user selected this, etc), so I don’t really think it’s wrong to have the delegate adapt to stateful information on the ViewModel.

    Anyway, this is a bit wordy… the take-away is “do whatever feels comfortable”.

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

Sidebar

Related Questions

I thought I would post this here not so much as a question but
Thought I would ask the knowledgeable StackOverflow community a question that was on my
I thought that :folddoc execute v:foldstart.p would work, but it only repeatedly returns the
I thought calling Equals() on two empty Lists would return true, but that's not
I thought I heard that py2exe was able to do this, but I never
I thought I'd offer this softball to whomever would like to hit it out
I thought I would be smart and create member functions that accepted output iterators.
I thought that would have been simple but it is not working. I can,
Thought my range of search options would easily find this. I wish to combine
I thought this would be fairly easy, but I'm totally baffled. I want one

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.