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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:16:14+00:00 2026-06-10T19:16:14+00:00

Well after fiddling with MVVM light to get my button to enable and disable

  • 0

Well after fiddling with MVVM light to get my button to enable and disable when I want it to… I sort of mashed things together until it worked.

However, I just know I’m doing something wrong here. I have RaiseCanExecuteChanged and CanExecute in the same area being called. Surely this is not how it’s done?

Here’s my xaml

<Button Margin="10, 25, 10, 25" VerticalAlignment="Center" HorizontalAlignment="Center" Width="50" Height="50" Grid.Column="1" Grid.Row="3" Content="Host">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <mvvmLight:EventToCommand Command="{Binding HostChat}" MustToggleIsEnabled="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>

And here’s my code

public override void InitializeViewAndViewModel()
{
    view = UnityContainer.Resolve<LoginPromptView>();
    viewModel = UnityContainer.Resolve<LoginPromptViewModel>();
    view.DataContext = viewModel;
    InjectViewIntoRegion(RegionNames.PopUpRegion, view, true);

    viewModel.HostChat = new DelegateCommand(ExecuteHostChat, CanHostChat);
    viewModel.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ViewModelPropertyChanged);
}

void ViewModelPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    if (e.PropertyName == "Name" || e.PropertyName == "Port" || e.PropertyName == "Address")
    {
        (viewModel.HostChat as DelegateCommand).RaiseCanExecuteChanged();
        (viewModel.HostChat as DelegateCommand).CanExecute();
    }
}

public void ExecuteHostChat()
{
}

public bool CanHostChat()
{
    if (String.IsNullOrEmpty(viewModel.Address) ||
        String.IsNullOrEmpty(viewModel.Port) ||
        String.IsNullOrEmpty(viewModel.Name))
    {
        return false;
    }
    else
        return true;
}

See how these two are together? Surely that can’t be right. I mean… it WORKS for me… but something seems wrong about it. Shouldn’t RaiseCanExecuteChanged call CanExecute? It doesn’t… and so if I don’t have that CanExecute in there, my control never toggles its IsEnabled like I need it to.

(viewModel.HostChat as DelegateCommand).RaiseCanExecuteChanged();
(viewModel.HostChat as DelegateCommand).CanExecute();

EDIT:

If I end up using the Command property of button to bind my command to… everything works fine. I can remove the CanExecute and just leave the RaiseCanExecuteChanged and everything works brilliantly.

Like this… this works just fine.

<Button Command="{Binding HostChat}" Margin="10, 25, 10, 25" VerticalAlignment="Center" HorizontalAlignment="Center" Width="50" Height="50" Grid.Column="1" Grid.Row="3" Content="Host">
</Button>

void ViewModelPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    if (e.PropertyName == "Name" || e.PropertyName == "Port" || e.PropertyName == "Address")
    {
        (viewModel.HostChat as DelegateCommand).RaiseCanExecuteChanged();
        //(viewModel.HostChat as DelegateCommand).CanExecute();
        //CommandManager.InvalidateRequerySuggested();
    }
}
  • 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-10T19:16:15+00:00Added an answer on June 10, 2026 at 7:16 pm

    CanExecute method only returns whether the command can be executed or not. It doesn’t do anything else. You only need RaiseCanExecuteChanged. RaiseCanExecuteChanged will call CanHostChat in your case.

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

Sidebar

Related Questions

I've got an after insert trigger that works well. However, I want it to
Well after a while of scratching my head and going huh? trying to figure
Well looks too simple a question to be asked but i asked after going
Well how could I change the before image to the after image by using
After much searching and googling I am coming back to the well. I have
Tomcat has got that well-known memory leak problem that causes PermGen space errors after
here's a Fusion Tables map that's broken after a search. It does everything well
I am using AVPlayer it is working perfectly on device as well, but after
Well after much messing about I have finally got a query that gives sales
Well After you edit in a row in this table i've created on focusout

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.