Herrozerro
Herrozerro

Reputation: 1681

Using Commands in WPF

I have been trying to work through this example for using commands in WPF and I am running into some issues.

I have installed MVVMLight from nuget and have been following along as best I can. Bit I am getting Issues.

My ViewModel:

 Class BoreModel
 {
    public ICommand Updatesql
    {
        get; internal set;
    }

    private void CreateUpdatesql()
    {
        Updatesql = new RelayCommand(UpdatesqlExecute);
    }

    private void UpdatesqlExecute()
    {
        FormSql.ProcessFormLocal(form1);
    }

    public BoreModel(string BusinessUnit, string TaskID)
    {
        CreateUpdatesql();
    }
}

My Xaml:

    <Button Click="{Binding Path=Updatesql}" Content="Button" HorizontalAlignment="Left" Margin="206,211,0,0" VerticalAlignment="Top" Width="75"/>

The code behind:

    public MainWindow()
    {
        DataContext = new BoreModel();
        InitializeComponent();
    }

I get a error pointing to the bottom line: "'Provide value on 'System.Windows.Data.Binding' threw an exception.' Line number '12' and line position '17'."

any ideas?

Upvotes: 2

Views: 396

Answers (2)

JSJ
JSJ

Reputation: 5691

I think you just forgot to set Command. Instead of setting command binding you mistakanlly set Binded with Click Event.

 <Button Command="{Binding Path=Updatesql}" ..../>

Upvotes: 0

Michael Gunter
Michael Gunter

Reputation: 12811

You should be using the Command property, not the Click event.

<Button Command="{Binding Updatesql}" ...

Upvotes: 3

Related Questions