Hi! I got the following situatino:
I derivated XamGrid to make my custom grid and I create dinamically some column. One of then is a CheckBoxColumn that binds into a property named "Selecionado".
What I need is to create in the header of this column a checkbox that check/uncheck all checkboxes in this column.
Pretty simple, but I create this template dinamically using an StyleWrapper I build. In my style dictionary i declared a DataTemplate that contais a checkbox, as shown above.
<DataTemplate x:Name="ucGridPermissaoColSelecionadoHeaderTemplate" >
<CheckBox x:Name="ckbTodos" HorizontalAlignment="Center" />
</DataTemplate>
When my grid is instatiated, I do the following, where StyleWrapper.GetItem<DataTemplate> return the DataTemplate i`ve shown before. How do I do that???
CheckBoxColumn colSelecionado = new CheckBoxColumn();
colSelecionado.HeaderTemplate =
StyleWrapper.GetItem<DataTemplate>("ucGridPermissaoColSelecionadoHeaderTemplate");
I am not sure what the question is here.
Does your GetItem return a valid DataTemplate? Are you not getting that value? Could you clarify what you are asking?
The DataTemplate as written isn't going to do much, just be Checkbox. You would need to attach an event handler (or two) to it to function.
The question is: How do I add an event Handler to Checked in this Checkbox? This template is in my resource dictionary and my grid is a class that derivates from XamGrid. The GetItem method returns a valid DataTemplate. All I need is know how do add this event handler. Thanks!
Hi,
You can actually create a custom command using our commanding framework to pretty easily achieve this:
public class MyCommandSource : CommandSource
{
public bool IsChecked
get;
set;
}
protected override ICommand ResolveCommand()
if (IsChecked)
return new CheckedCommand();
else
return new UncheckedCommand();
public class CheckedCommand : ColumnCommandBase
protected override void ExecuteCommand(Column col)
// perform logic:
public class UncheckedCommand : ColumnCommandBase
<DataTemplate>
<CheckBox Content="Select All">
<ig:Commanding.Commands>
<local:MyCommandSource EventName="Checked" IsChecked="True" ></local:MyCommandSource>
<local:MyCommandSource EventName="Unchecked" IsChecked="False" ></local:MyCommandSource>
</ig:Commanding.Commands>
</CheckBox>
Hope this helps,
-SteveZ
Hi Steve
I'm trying to run your suggested code for the check none/all header and got it almost working. The only issue I'm having is that I cannot get both commands (Checked, Unchecked) to get fired.
It always fires the last command I put in DataTemplate xml (Unchecked in your sample), If I switch them (first unchecked then checked) it will only fire checked command.
Any suggestions?
Rodolfo.
You can access the xamGrid with the following code:
XamGrid grid = col.ColumnLayout.Grid;
Note: i'm assuming your CheckboxColumn is bound. If so, instead of looping through the rows, i'd recommend accessing the ItemSource, and walking through the collection and accessing your data directly. It should produce faster results.
Dahhh. You are right, my bad. Now it's firing both events.
Last issue following the same sample.
Once in :
// How can I access grid's rows to change all/none checkboxes on my template column if all I have is "col"?
// I cannot access the grid directly because this is another class.
// I checked Column properties but didn't see any one that could give me the grid, is that possible?
The name of the property you want to set is Commands (plural) not Command.
<local:MyCommandSourceUnchecked EventName=""Unchecked""></local:MyCommandSourceUnchecked>
<local:MyCommandSourceChecked EventName=""Checked""></local:MyCommandSourceChecked> </ig:Commanding.Commands>
I think I have everything just like you posted it.
I have a zip proj with the sample. I'm using 2 different commands but it is the same if I do it just like you have it.
Here goes the sample.
Hi Rodolfo,
I just tested this out, and its still working.
Are you doing exactly what i was doing in the example code? And setting the EventName to be 2 separate events?
Or are you using a button, and hooking into the click event for both commands?
Do you have a sample that you can send that shows the issue?