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
30
Adding buttons to rows in datagrid
posted

Hi There,

I'm just starting out with WPF and would like to add buttons to each row in a xaml grid with each buttons event handler being able to tell which row the button was clicked on.  I haven't seen this in any of the samples.  Does anyone have any examples of this?

I could get the user to select the row and click one common button however the application must be very quick to use and having icons/buttons in the rows would cut the clicks necessary in half.

Thanks in advance,

Rob

  • 245
    posted

     I created a an unbound field and then styled/template the cellvaluepresenter.  hope this helps.

     

    <igDP:UnboundField>
                                    <igDP:Field.Settings>
                                        <igDP:FieldSettings CellMaxWidth="40" LabelMaxWidth="40" CellMinWidth="40" LabelMinWidth="40">
                                         <igDP:FieldSettings.CellValuePresenterStyle>
                                            <Style TargetType="{x:Type igDP:CellValuePresenter}">
                                                <Setter Property="Visibility" Value="Hidden" />
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                                                            <Grid Width="50">
                                                                <Grid.ColumnDefinitions>
                                                                    <ColumnDefinition Width="20" />
                                                                    <ColumnDefinition Width="20" />
                                                                </Grid.ColumnDefinitions>
                                                                    <Button  Grid.Column="0" Width="15" Height="15"
                                                                        Command="cust:PopupControl.ShowCommand"
                                                                        CommandTarget="{Binding ElementName=ModifySrpCategoryPopup}"
                                                                        CommandParameter="{TemplateBinding Record, Converter={StaticResource DataRecordConverter}}"
                                                                        ToolTip="{g:LocalizedResource Name=ModifyCommand}"
                                                                        Style="{DynamicResource EditButtonStyle}"
                                                                        HorizontalAlignment="Center" />
                                                                    <Button  Grid.Column="1" Width="15" Height="15"
                                                                        Command="rmsClient:RmsCommands.Delete" HorizontalAlignment="Center" ToolTip="Delete"
                                                                        CommandParameter="{TemplateBinding Record, Converter={StaticResource DataRecordConverter}}"
                                                                        Style="{DynamicResource DeleteButton}"/>
                                                                </Grid>
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                                            <Setter Property="Visibility" Value="Visible"/>
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                               </Style>
                                            </igDP:FieldSettings.CellValuePresenterStyle>
                                        </igDP:FieldSettings>
                                   </igDP:Field.Settings>
                               </igDP:UnboundField>