I have a style that puts a button in an UnboundField of a row. The button calls the MyCommand method on MyClass. Everything works fine, except the Parameter to the event handler is null. I'd like to have the button do an expand all on all the child records, so I was hoping to get to the record that contains the CellValuePresenter, which is why I'm passng Record as the parameter.
Why is the record field null? What should I bind to so that I can iterate and expand child records of the buttons row?
<Style x:Key="myStyle" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{x:Static igThemes:DataPresenterGeneric.CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Button Content="+" HorizontalAlignment="Center" VerticalAlignment="Center"
Command="local:MyClass.MyCommand"
CommandParameter="{Binding Path=Record}"
/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Hello,
You should be getting an error showing that Record property cannot be found. This is because it will try to resolve it from the CellValuePresenter's DataContext which is the DataRecord. If you want this binding to find the recond, you need to set the RelativeSource to TemplatedParent or FindAncestor, AncestorType-CellValuePresenter.
Also, you could consider binding directly to the DataPresenterBase.ExpanRecord command
Thanks, Alex. This fixed the issue. Should point, though, that I did not get an error at compile time or runtime. The Parameter was just null in the event handler, which was a bit frustrating.
I don't see anything in the docs about an ExpandRecord command on DataPresenterBase. Can you give a little more info?
Sorry, it was a typo. I was referring to DataPresenterCommands rather than DataPresenterBase. You can execute a command in procedural code either by calling the ExecuteCommand method of the XamDataGrid and passing any of these commands as parameter. There are samples on how you can bind to these commands in the xaml in the XamFeatureBrowser under XamDataGrid - DataBinding and Interaction - xamDataGrid Commands.