Reputation: 1261
I'm using mvvm light with wpf.
Currently i can pass string parameter to viewmodel's command like below:
<TextBox Height="23" TextWrapping="Wrap" Text="TextBox" Name="textbox1"/>
<Button Command="{Binding ShowMessage}" Content="Click Me"
CommandParameter="{Binding ElementName=textbox1, Path=Text}" />
My question is how to pass composite type like Person to a command of ViewModel?
Thanks
Upvotes: 1
Views: 471
Reputation: 12295
<TextBox Height="23" TextWrapping="Wrap" Text="TextBox" Name="textbox1" Tag="{Binding Person}"/>
<Button Command="{Binding ShowMessage}" Content="Click Me"
CommandParameter="{Binding ElementName=textbox1, Path=Tag}" />
you can make use of Tag Property of TextBox but I think there is something wrong with your MVVM implementation,It is the ViewModel that holds the data for your view. But here you sending it from View to VM . I mean Person should be automatically there in your VM instead of sending it from View.
Upvotes: 1