Passing a string property to a command via a button CommandParameter in .NET 6
Hello
So I'm trying to pass a string (that's bound to a text field via a data context
This does however not work, pressing the button does call the command and I do see
in the program's output, however after testing
which produces
What am I doing wrong with my previous binding? Maybe this is the wrong way of handling button presses? I've seen people just use
So I'm trying to pass a string (that's bound to a text field via a data context
<TextBox [...] Text="{Binding SearchString}"/> which I made sure already works) using a button's CommandParameter. The relevant button code is as follows (I've hidden layout arguments) PerformSearch is a property of the class MainViewModel that I have defined as a custom classThis does however not work, pressing the button does call the command and I do see
in the program's output, however after testing
parameter is null. If I pass a string directly instead of using a binding, I do get the string as an outputwhich produces
What am I doing wrong with my previous binding? Maybe this is the wrong way of handling button presses? I've seen people just use
CommandParameter="Binding" and pass the whole ViewModel, and it does indeed pass the whole viewmodel, but I feel like it defeats the purpose of having a separate class handle the command.