Hello.
I'am trying to bind ViewModel property to a CommandProperty of a GridViewCheckBox inside of CreateCellElement. Unfortunately the binded command doesn't run while clicking on checkbox. Any ideas why this isn't working?
I'm posting the code where I belive is the mistake. I have made a test Visual Studio 2013 project to try to solve this. It is enable to download here: HERE
Creating cell element:
internal
class
GroupDataGridCheckBoxColumn : GridViewCheckBoxColumn
{
private
readonly
Group _group;
public
GroupDataGridCheckBoxColumn(Group group)
:
base
()
{
this
._group = group;
this
.AutoSelectOnEdit =
true
;
this
.EditTriggers = GridViewEditTriggers.CellClick;
}
public
override
FrameworkElement CreateCellElement(GridViewCell cell,
object
dataItem)
{
GridViewCheckBox checkBox =
base
.CreateCellElement(cell, dataItem)
as
GridViewCheckBox;
/// <THIS DOESNT WORK>
/* Set Command binding */
Binding commandBinding =
new
Binding(
"DataContext.AddOrRemoveGroupCommand"
);
commandBinding.RelativeSource =
new
RelativeSource(RelativeSourceMode.FindAncestor,
typeof
(Window), 1);
checkBox.SetBinding(CheckBox.CommandProperty, commandBinding);
/* Set Command parameter */
MultiBinding commandParameterBinding =
new
MultiBinding();
commandParameterBinding.Converter =
new
CommandParameterMultiConverter();
commandParameterBinding.Bindings.Add(
new
Binding(
"IsChecked"
) { RelativeSource = RelativeSource.Self });
commandParameterBinding.Bindings.Add(
new
Binding(
"."
));
//the employee object
commandParameterBinding.Bindings.Add(
new
Binding(
"."
) { Source =
this
._group });
//the group object
checkBox.SetBinding(CheckBox.CommandParameterProperty, commandParameterBinding);
/// <THIS DOESNT WORK/>
return
checkBox;
}
}
Any ideas? This error consumed 1 day of my work for now..