jeudi 18 février 2016

Checkbox inside Datagrid

Issue


I can't seem to be able to fire a method inside my ViewModel when a Checkbox is checked inside my DataGrid.

Each row will have a Checkbox inside the row and when the Checkbox has been selected/unselected, I want to trigger a method in my ViewModel which will update a database.

Code


I have this Datagrid inside my XAML:

    <DataGrid x:Name="dg_chapters" ItemsSource="{Binding Chapters}" SelectedItem="{Binding Chapter}" SelectionMode="Single" Background="Transparent" BorderBrush="#e5e5e5" CellStyle="{StaticResource episodeDataGridCell}" RowHeaderWidth="0" GridLinesVisibility="None" HorizontalAlignment="Stretch" Grid.Row="4" VerticalAlignment="Stretch" AutoGenerateColumns="False" Grid.RowSpan="1" Grid.Column="1" Grid.ColumnSpan="7">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Description}" CanUserResize="False" ClipboardContentBinding="{x:Null}" Header="Chapter" Width="90"/>
            <DataGridTextColumn Binding="{Binding Appearance}" CanUserResize="False" ClipboardContentBinding="{x:Null}" Header="Player" Width="90"/>
            <DataGridTextColumn Binding="{Binding Channel}" CanUserResize="False" ClipboardContentBinding="{x:Null}" Header="Channel" Width="100"/>
            <DataGridTextColumn Binding="{Binding Mode}" ClipboardContentBinding="{x:Null}" Header="Mode" Width="80"/>
            <DataGridCheckBoxColumn Binding="{Binding Protected}" Header="Protected" Width="80"/>
        </DataGrid.Columns>
    </DataGrid>

As you can see at the bottom is my Checkbox column. In my ViewModel i tried to create a command to handle the selected/deselection of the Checkbox:

    public ICommand Protected
    {
        get { return new DelegateCommand<object>(Protected_Click); }
    }

And then I created the Protected method:

    private void Protected_Click(object obj)
    {
        //DOES NOT HIT.
    }

Can anyone see where I am going wrong and how I can get this functionality to work?




Aucun commentaire:

Enregistrer un commentaire