Search code examples
c#wpftelerikradgridview

RadGridView Button Column Content Binding to DataMember


I have a telerik rad grid view and assigned buttons to one of the columns using DataTemplate.

        <telerik:RadGridView ItemsSource="{Binding AllJobsCollection}" 
                         Grid.Row="2"
                         SelectedItem="{Binding SelectedJob}">

        <!--Jobs List Columns-->
        <telerik:RadGridView.Columns>

            <!--Pin button Column-->
            <telerik:GridViewColumn>
                <telerik:GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <telerik:RadButton
                            Command="{Binding Path=DataContext.PinCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataControl}} }"            
                            CommandParameter="{Binding}">
                        </telerik:RadButton>
                    </DataTemplate>
                </telerik:GridViewColumn.CellTemplate>
            </telerik:GridViewColumn>

            <telerik:GridViewDataColumn Header="Job" 
                                        Width="Auto"
                                        IsReadOnly="False"
                                        DataMemberBinding="{Binding Name}"/>

        </telerik:RadGridView.Columns>
    </telerik:RadGridView>

My question is how can I set the content of the button using DataMemberBinding.

I have a data table and i can pin some of the items and i change their Pinned property in database. I want to get the pinned property and set the buttons content accordingly.


Solution

  • You can't use DataMemberBinding within a CellTemplate. But you can bind the Content property to the any property of the current item, e.g.:

    <telerik:RadButton
        Command="{Binding Path=DataContext.PinCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataControl}} }"            
        CommandParameter="{Binding}"
        Content="{Binding IsPinned}">