This is a migrated thread and some comments may be shown as answers.

Item binding within ControlTemplate

3 Answers 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rutger Kars
Top achievements
Rank 1
Rutger Kars asked on 06 Dec 2012, 09:39 AM
Hi,

I'm having problems with binding my items within a gridview controltemplate. I've already followed the WPF examples of it (GridView Examples - Appearence - Custom Row Layout), but whatever I try, binding isn't working when the RowStyle/ControlTemplate is active.

Below a simplified code snippet from the example, but with my own binding names:
<Grid>
        <Grid.Resources>
            <ControlTemplate x:Key="MyCustomRowTemplate" TargetType="telerik:GridViewRow">
                <Border x:Name="rowsContainer" BorderThickness="0,0,0,1">
                    <Grid Width="Auto" HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="20"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="150" />
                        </Grid.ColumnDefinitions>
 
                        <TextBlock Text="Data1: " Margin="5,0,0,0" FontWeight="Bold" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left"  />
                        <TextBlock Text="{Binding Data1}" Margin="5,0,0,0" Grid.Row="0" Grid.Column="1"  VerticalAlignment="Center" HorizontalAlignment="Left"/>
                        <TextBlock Text="Data2: " Margin="5,0,0,0" FontWeight="Bold" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center"  />
                        <TextBlock Text="{Binding Data2}" Margin="5,0,0,0" Grid.Row="1" Grid.Column="1"  VerticalAlignment="Center" HorizontalAlignment="Left"/>
                        <TextBlock Text="Data3: " Margin="5,0,0,0" FontWeight="Bold" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center"  />
                        <TextBlock Text="{Binding Data3}" Margin="5,0,0,0" Grid.Row="2" Grid.Column="1"  VerticalAlignment="Center" HorizontalAlignment="Left"/>
                    </Grid>
                </Border>
            </ControlTemplate>
            <Style x:Key="rowStyle" TargetType="telerik:GridViewRow">
                <Setter Property="Template" Value="{StaticResource MyCustomRowTemplate}" />
            </Style>
        </Grid.Resources>
 
        <telerik:RadGridView RowStyle="{StaticResource rowStyle}" ItemsSource="{Binding Contacts}" ShowGroupPanel="False"
             BorderThickness="0" IsFilteringAllowed="False" AutoGenerateColumns="False" CanUserFreezeColumns="False" >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Data1" DataMemberBinding="{Binding Data1}"/>
                <telerik:GridViewDataColumn Header="Data2" DataMemberBinding="{Binding Data2}"/>
                <telerik:GridViewDataColumn Header="Data3" DataMemberBinding="{Binding Data3}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>

You see the bindings to Data1, Data2, Data3, but as soon as I run it, those field stay empty, see screenshot 1

However, when I remove the RowStyle="{StaticResource rowStyle}" in my RadGridView then the Data is displayed correctly in the row, see screenshot 2

I've already tried binding with Path=, or CurrentItem.Data1 and several other options, but none of it works, while it works in de example.

I'm problably missing something, but if I compare my code with the example, I don't see any difference in binding, so any help would be appreciated.

Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 06 Dec 2012, 01:34 PM
Hello,

 What kind of collection you've bound to the grid ItemsSource? If this is DataTable you will need to use square brackets for your Bindings in templates. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rutger Kars
Top achievements
Rank 1
answered on 06 Dec 2012, 01:42 PM
It's an observableCollection of Contact's, which is an enitity framework class, mapped to the db.
Tried binding to {Binding [Data1]} just to be sure, but without any results
0
Rutger Kars
Top achievements
Rank 1
answered on 06 Dec 2012, 03:30 PM
I found the issue... I binded it again to an observablecollection of contactviewmodels, which I just created to try another solution. This solution was working, so I was looking further.
And so I found out that my EF properties where in capitals.. Somehow binding directly is case insensitive, and binding via the controltemplate is case sensitive.
Tags
GridView
Asked by
Rutger Kars
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Rutger Kars
Top achievements
Rank 1
Share this question
or