I have a checkbox for each row in the listview. I want to bind the Checkbox OnClick to my command in the view model. But its not binding to my Command. What should I do? Below is my xaml and Viewmodel
Xaml:
<Grid>
<ListView Name="lstdemo" ItemsSource="{Binding obcollection}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chk" IsChecked="{Binding IsChecked,Mode=TwoWay,NotifyOnTargetUpdated=True}" Command="{Binding Path=UpdateCommand}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</Grid>
ViewModel:
public class MyViewModel
{
private List<Demo> lstdemo;
private ObservableCollection<Demo> Obcollection;
private SampleDb db;
public MyViewModel()
{
db = new SampleDb();
lstdemo = db.Demoes.ToList();
Convert();
}
public void Convert()
{
Obcollection = new ObservableCollection<Demo>(lstdemo);
}
public ObservableCollection<Demo> obcollection
{
get { return Obcollection; }
set { Obcollection = value; }
}
private ICommand mUpdater;
public ICommand UpdateCommand
{
get
{
if (mUpdater == null)
mUpdater = new Updater();
return mUpdater;
}
set
{
mUpdater = value;
}
}
public class Updater : ICommand
{
#region ICommand Members
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
if (parameter == null)
{
MessageBox.Show("Hello");
}
}
#endregion
}
}