I've implemented a hierarchical grid and have used the checkbox sample as a baseline. The problem I'm having is that each of my headers (n-level) need to call their appropriapte View Model to do the checking/unchecking of their children.
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding ???" />
Each level ViewModel contains a list and a bool field. I have tried several things but cannot seem to get the right object reference.
Any ideas or suggestions?
chr15t1an
As far as I understand, you want to mark the row as active row of the grid if you click on the checkbox in the rowselector. Tbh you make the row active when you click on any of it's cells, so I don't see the point of it.
If I were you I would not use checkbox, but radiobutton here, because there could be only one active row in the grid. Besides setting the record's IsActive property to true, you have to set the grid's ActiveRecord property to the record you want.
Is there a way to modify the style such that when the check box in the row selecter is checked, the row it belongs to is made the Active row?
Thanks,
Yes, if you look closely at my xaml, you'll see I did the same thing, albeit with different names to protect the innocent. That is the easy part, binding your data is the more difficult issue. Follow my code behind and you should be on your way.
Just an fyi - if "AllMembersAreChecked" and all related members/methods are not in the immediate DataContext, the above will never work. Be sure you get all of your hierarchial data in the DataContext where it is clearly visible.
Glenn
The easiest way to force checkbox in HeaderPrefixArea to respect grouping is to write a custom binding just like Vlad said.
<Style TargetType="{x:Type igDP:HeaderPrefixArea}" BasedOn="{x:Null}"> <Setter Property="Visibility" Value="Visible" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:HeaderPrefixArea}"> <CheckBox x:Name="cbHeaderPrefix" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=DataPresenter.DataContext.AllMembersAreChecked, Mode=TwoWay}" IsEnabled="{Binding Path=DataPresenter.DataContext.CanSelectAnyBook, Mode=OneTime}" Tag="{Binding Path=Record.Value, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:GroupByRecordPresenter}}, Mode=OneTime}" /> <ControlTemplate.Triggers> <DataTrigger Binding="{Binding ElementName=cbHeaderPrefix, Path=Tag}"> <DataTrigger.Value> <Business:PreMarkCategory>UnableToProceed</Business:PreMarkCategory> </DataTrigger.Value> <Setter Property="IsChecked" TargetName="cbHeaderPrefix" Value="false" /> <Setter Property="IsEnabled" TargetName="cbHeaderPrefix" Value="false" /> </DataTrigger> <DataTrigger Binding="{Binding ElementName=cbHeaderPrefix, Path=Tag}"> <DataTrigger.Value> <Business:PreMarkCategory>Warnings</Business:PreMarkCategory> </DataTrigger.Value> <Setter Property="IsChecked" TargetName="cbHeaderPrefix" Value="{Binding Path=DataPresenter.DataContext.AllWarningMembersAreChecked, Mode=TwoWay}" /> <Setter Property="IsEnabled" TargetName="cbHeaderPrefix" Value="{Binding Path=DataPresenter.DataContext.CanSelectAnyWarningBook, Mode=OneTime}" /> </DataTrigger> <DataTrigger Binding="{Binding ElementName=cbHeaderPrefix, Path=Tag}"> <DataTrigger.Value> <Business:PreMarkCategory>OkToProceed</Business:PreMarkCategory> </DataTrigger.Value> <Setter Property="IsChecked" TargetName="cbHeaderPrefix" Value="{Binding Path=DataPresenter.DataContext.AllOkMembersAreChecked, Mode=TwoWay}" /> <Setter Property="IsEnabled" TargetName="cbHeaderPrefix" Value="{Binding Path=DataPresenter.DataContext.CanSelectAnyOkBook, Mode=OneTime}" /> </DataTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
Peter,
I have included a zip file of my code (xaml and code behind). Read through it and I think you'll see how it's done. Drop me a note if still confused. It contains everything you need to do the same. GroupByRecord is not as elegant as it sounds.
No guarantees implied, but it works very well for my needs.
Cheers,