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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:41:07+00:00 2026-06-15T11:41:07+00:00

I’m new to WPF and MVVM so bear with me. Basically, I am creating

  • 0

I’m new to WPF and MVVM so bear with me.

Basically, I am creating an application to enable users to enter their organisation details into a database.

within my WPF application I’m creating, I have a View Model that contains properties, commands and entity framework methods (I know this isn’t the correct way to use MVVM, but I’m learning slowly how to achieve it).

On one of my views, it is a tab control, allowing a user to enter different organisation details into the database and then, on another view, I have a data grid to show what they have entered to enable the user to update the content when needed.

which leads me to my question. So far I have validated my commands so that when certain fields are empty, then the button will not be active but once they have been entered, they will be activated. Like so;

           private ICommand showAddCommand;
    public ICommand ShowAddCommand
    {
        get
        {
            if (this.showAddCommand == null)
            {
                this.showAddCommand = new RelayCommand(this.SaveFormExecute, this.SaveFormCanExecute);//i => this.InsertOrganisation()
            }

            return this.showAddCommand;
        }
    }

    private bool SaveFormCanExecute()
    {
        return !string.IsNullOrEmpty(OrganisationName) && !string.IsNullOrEmpty(Address) && !string.IsNullOrEmpty(Country) && !string.IsNullOrEmpty(Postcode)
            && !string.IsNullOrEmpty(PhoneNumber) && !string.IsNullOrEmpty(MobileNumber) && !string.IsNullOrEmpty(PracticeStructure) && !string.IsNullOrEmpty(PracticeType) && !string.IsNullOrEmpty(RegistrationNumber); 
    }

    private void SaveFormExecute()
    {
        InsertOrganisations();
    }

  Xaml:
  <Button Content="Save" Grid.Column="1" Grid.Row="18" x:Name="btnSave" VerticalAlignment="Bottom" Width="75" Command="{Binding ShowAddCommand}"/>

But what I was hoping to achieve is that, once a user has entered in 1 organisation into the database, then the command doesn’t become active altogether and prevents the user from entering another organisation by accident. the purpose is to only allow 1 organisation to be added, no more or no less.

Is this possible?

  • 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-15T11:41:08+00:00Added an answer on June 15, 2026 at 11:41 am

    Two things. 1), I’d recommend editing your RelayCommand to take an Action as follows:

        private Action<object> _execute;
        private Predicate<object> _canExecute;
    
        public RelayCommand(Action<object> execute, Predicate<object> canExecute)
        {
            if (execute == null)
                throw new ArgumentNullException("execute");
            _execute = execute;
            _canExecute = canExecute;
        }
    
        //[DebuggerStepThrough]
        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute(parameter);
        }
    

    This may not help your immediate issue, but it will make your code more reusable, as you’ll be able to bind certain elements from your View as parameters in your ICommand for both CanExecute testing and Execution (or if you won’t require this, just pass null as the object parameter in the ICommand.Execute and don’t bind anything to CommandParameter in the View)

    Furthermore, in your RelayCommand, make sure you are overriding CanExecuteChanged as follows:

        public override event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
    

    This will trigger your ICommand to recheck CanExecute when changes are made by the user (and is most likely the piece that you’re missing).

    Finally, once this is done, it’s just a matter of including your criteria in CanExecute (either from the CommandParameter OR from something in your VM).

    I hope this helps.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.