Hopefully this is a simple MVVM question, but I'm trying to grasp command parameters.
I have a user select an item from the ListBox, and click "Delete Selected". The ListBox binds SelectedItem to "SelectedTemplate". My button XAML looks like so:
<Button CommandParameter="{Binding SelectedTemplate}" Command="{Binding DeleteTemplateCommand}" Content="Delete Selected"/>
When i get to my execute command, I'm reading the parameter from the Command. However, I also can access "SelectedTemplate". If i use the passed parameter, I'd then have to convert it to the correct objecttype before removing the object, versus just going ahead and removing "selectedTemplate"
public void DeleteTemplate(object template)
{
Convert.ChangeType(template, typeof(Template));
if (template == SelectedTemplate )
{
_ESTContext.Templates.Remove(SelectedTemplate);
}
}
My question here is that to me it seems both satisfy the MVVM philosophy, is there a benefit/detriment to using one or the other?