The title pretty much sums it up. I've been trying to use the button's CommandParameter but I'm not sure what it should be and what additional code I need in my ViewModel class. Any help would be appreciated.
XAML:
<ItemsControl>
<StackPanel Orientation="Horizontal">
<Button Command="{Binding ButtonClick}" Width="150" Margin="5" Height="22" HorizontalAlignment="Left">Click</Button>
</StackPanel>
<ListView Name="listView" Grid.Row="1" BorderThickness="0" ItemsSource="{Binding myObjects}">
<ListView.View>
<GridView>
<GridViewColumn Header="Space ID" DisplayMemberBinding="{Binding ID}" Width="Auto" />
</GridView>
</ListView.View>
</ListView>
</ItemsControl>
ViewModel C#:
public ICommand ButtonClick
{
get { return new DelegateCommand(BtnClick); }
}
private void BtnClick()
{
//Access selected object of type myObject here.
}
DelegateCommand class:
public class DelegateCommand : ICommand
{
private readonly Action _action;
public DelegateCommand(Action action)
{
_action = action;
}
public void Execute(object parameter)
{
_action();
}
public bool CanExecute(object parameter)
{
return true;
}
}