2

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.

1 Answers1

1

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}">
mm8
  • 163,881
  • 10
  • 57
  • 88
  • All the properties of my items are described through datamemberbinding. I cannot acces any property of my item, because they are loaded from a collection. – Avag Akopov May 14 '18 at 15:05
  • What property do you want to bind the Content property and where is this property defined? – mm8 May 14 '18 at 15:08
  • My collection is a collection of the items of the Job class. This class has Name property, plenty of others and IsPinned property. I want to bind button content to the IsPinned property. – Avag Akopov May 14 '18 at 15:11
  • Then it should be `Content="{Binding IsPinned}"` as per my updated answer. – mm8 May 14 '18 at 15:12