Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
280
XamDataGrid and button issue
posted

Hi,

I have an issue with the XamDataGrid and command parameter for my button on each row. By searching around for different solutions I found one that should work, but for some reason the DataItem of the CellValuePresenter is null. There are no errors in the Output-window, so the binding should work. I can verify that my command's CanExecute method is called, but the object parameter is null instead of the expected object.

My code for the unbound field in my grid is:

                                            <igWPF:UnboundField Name="OpenButton" Label="" Width="1*">
                                                <igWPF:UnboundField.Settings>
                                                    <igWPF:FieldSettings>
                                                        <igWPF:FieldSettings.CellValuePresenterStyle>
                                                            <Style TargetType="{x:Type igWPF:CellValuePresenter}">
                                                                <Setter Property="Template">
                                                                    <Setter.Value>
                                                                        <ControlTemplate>
                                                                            <igWPF:ButtonTool x:Name="GridAddWallButton" Content="{x:Static r:SubProjectResources.WallGridFieldOpenButton}" Command="{Binding DataPresenter.DataContext.OpenWallCommand}" CommandParameter="{Binding DataItem}" HorizontalContentAlignment="Center"/>
                                                                        </ControlTemplate>
                                                                    </Setter.Value>
                                                                </Setter>
                                                            </Style>
                                                        </igWPF:FieldSettings.CellValuePresenterStyle>
                                                    </igWPF:FieldSettings>
                                                </igWPF:UnboundField.Settings>
                                            </igWPF:UnboundField>

/ FW

  • 1560
    Offline posted
    Hello,

    Thank you for the code-snippet you have provided.
     
    In order to pass the DataItem of the current CellValuePresenter's Record as a CommandParameter , an approach I can suggest you is to set the RelativeSource binding for the Command. 
    <Button x:Name="myButton" Width="25"
                                            Command="{Binding Path=DataContext.Cmd, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                            CommandParameter="{Binding DataItem}"/>

    Please test this approach on your side and let me know how it behaves. If this does not help you please feel free to provide your own sample. Remove any external dependencies and code that is not directly related to the issue, zip your application and attach in in this case.

    Having a working sample on my side, which I can debug, is going to be very helpful in finding the root cause of this behavior.

    Thank you for your cooperation. 

    Looking forward to hearing from you.

    Sincerely,
    Teodosia Hristodorova
    Associate Software Developer