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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:55:42+00:00 2026-05-23T17:55:42+00:00

I am trying to implement a WPF MVVM application. And I am a beginner

  • 0

I am trying to implement a WPF MVVM application. And I am a beginner in this platform. All I need is to implement a CanExecute method for my SaveCommand

Here is the code

WPF XML Code

        <Canvas Height="283" Name="canvas1" Width="321">
            <Label Canvas.Left="6" Canvas.Top="6" Content="First Name" Height="25" Width="91" />
            <Label Canvas.Left="6" Canvas.Top="37" Content="Last Name" Height="25" Width="91" />
            <TextBox Canvas.Left="103" Canvas.Top="10" Height="21"  Width="199" Text="{Binding Path=FirstName, UpdateSourceTrigger=PropertyChanged}"/>
            <TextBox Canvas.Left="103" Canvas.Top="37" Height="21"  Width="199" Text="{Binding Path=LastName, UpdateSourceTrigger=PropertyChanged}"/>
            <Button Canvas.Left="228" Canvas.Top="241" Content="Save" Height="23" Width="74" Command="{Binding SaveCommand}" />
            <TextBlock Canvas.Left="28" Canvas.Top="110" Height="19" Width="259" Text="{Binding Path=FullName}"/>
        </Canvas>

C# ViewModel code

    public CustomerViewModel(IEventAggregator eventAggregator, IUnityContainer container, ILoggerFacade logger)
        : base(eventAggregator, container, logger)
    {
        logger.Log("View Model Initialized", Category.Debug, Priority.None);
        InitializeCommands();
    }

    public DelegateCommand<object> SaveCommand { get; set; }

    private string firstName;

    public string FirstName
    {
        get { return firstName; }
        set { 
            firstName = value;
            RaisePropertyChanged("FirstName");
        }
    }

    private string lastName;

    public string LastName
    {
        get { return lastName; }
        set { 
            lastName = value;
            RaisePropertyChanged("LastName");
        }
    }
    private string fullName;

    public string FullName
    {
        get { return fullName; }
        set { 
            fullName = value;
            RaisePropertyChanged("FullName");
        }
    }


    private void InitializeCommands()
    {
        SaveCommand = new DelegateCommand<object>(OnSaveCommand, CanSaveExcute);

    }
    private bool CanSaveExcute(object obj)
    {
        if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName))
            return false;
        return true;
    }

    private void OnSaveCommand(object obj)
    {
        FullName = FirstName + " " + LastName;
    }

Without the can CanSaveExcute it works fine. After setting CanSaveExcute the button remains disable and does not enable on text change. As far as I have learned this is the way to go.

Please Show me what I am doing wrong.

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-23T17:55:42+00:00Added an answer on May 23, 2026 at 5:55 pm

    You should also raise the “CanExecuteChanged” event, otherwise the receiver would have to permanently revisit your command, to find out whether it can be executed. You can use the “RaiseCanExecuteChanged” method, described here

    Edit
    If you don’t mind the overhead, you can just call this.SaveCommand.RaiseCanExecuteChanged() after your call to RaisePropertyChanged("FullName"); in the property-setters. If you RaisePropertyChanged method is virtual, you could place the RaiseCanExecuteChanged() their.

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

Sidebar

Related Questions

I'm trying to implement a WPF application using MVVM (Model-View-ViewModel) pattern and I'd like
I am trying to implement the MVVM design patern for mt WPF application. In
So I've been trying to implement the MVVM pattern within a simple WPF application
I'm using wpf + mvvm and am trying to implement a conditional converter. Here
I am trying to implement my first WPF application using an MVVM design pattern.
I am trying to implement this MVVM pattern for the WPF form closing which
I'm writing my first WPF application and I'm trying to implement a fade animation
I'm a C# beginner and am trying to implement a numeric pad in WPF.
I'm trying to implement the MVVM pattern in WPF. I've followed Jeremy Alles's Very
I am trying to implement MVVM in a new project (based on WPF &

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.