Thomas Flinkow
Thomas Flinkow

Reputation: 5115

Xaml pass bound property to command

I have a TextBox bound to a string property on the ViewModel, and I have a Button with a Command. Now I want to pass the property itself if possible as a CommandParameter. Is this possible?

Xaml part:

<TextBox Text="{Binding FilePath, UpdateSourceTrigger=PropertyChanged}"/>
<Button Command="{Binding BrowseCommand}" CommandParameter="{Binding FilePath}" Content="..." />

And the Command looks like this, but what type do I have to put instead of the RelayCommand<?> and what do I need to bind the CommandParameter to?

public ICommand BrowseCommand => this.browseCommand ?? (this.browseCommand = new RelayCommand<?>(this.Browse));

Upvotes: 0

Views: 132

Answers (1)

mm8
mm8

Reputation: 169400

This should work if you are using the RelayCommand<T> class from MvvmLight:

public ICommand BrowseCommand => this.browseCommand ?? (this.browseCommand = new RelayCommand<string>(this.Browse));

private void Browse(string obj)
{

}

Upvotes: 1

Related Questions