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

[Solved] Binding within GridViewDataColumn Template uses different Types

1 Answer 125 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hans Notelteirs
Top achievements
Rank 1
Hans Notelteirs asked on 02 Sep 2009, 07:29 AM

Hi,

I'm having a problem databinding within a GridViewDataColumn Template. Here is the situation.
I have an Employee Class which has a list of SheduleActivities. This activity is like an appointment in outlook (startdate, endate, ...)
To display the activities of an Employee in the grid I made a SheduleWeek class, which has the properties Monday, Tuesday,..
of the type SheduleActivity. I first get the needed employees, create the SheduleWeeks with the employees and use the list of SheduleWeek as my ItemsSource.

var itemsSource = employees.Select(o => new SheduleWeek(o)).ToList();  
planningGrd.ItemsSource = itemsSource; 

As my columnTemplate I use the following code

<Controls:GridViewDataColumn Header="Maandag">  
                    <Controls:GridViewDataColumn.CellStyle> 
                        <Style TargetType="telerikGridView:GridViewCell">  
                            <Setter Property="Template">  
                                <Setter.Value> 
                                    <ControlTemplate TargetType="telerikGridView:GridViewCell">  
                                        <Grid> 
                                            <TextBlock x:Name="activityTxt" Text="{Binding}" TextWrapping="Wrap" FontWeight="Bold" /> 
                                            <GridItems:ActivityDetails DataContext="{Binding Monday}" Test="{Binding}" /> 
                                        </Grid> 
                                    </ControlTemplate> 
                                </Setter.Value> 
                            </Setter> 
                            <Setter Property="BorderThickness" Value="0,0,1,1"/>  
                        </Style> 
                    </Controls:GridViewDataColumn.CellStyle> 
                </Controls:GridViewDataColumn> 

The activityTxt I used just to check out which type I was binding to. When runnning the project it gives me the "SheduleWeek" type just like I expected. To display all the information I made a Usercontrol ActivityDetails. On this control I created a dependency property "Test" of the type string to check the type. And this string tells me the type I bind to is "SheduleActivity".
When I actualy want the SheduleWeek over there.

Can somebody explain to me why this happens and how to solve this?

Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Hans Notelteirs
Top achievements
Rank 1
answered on 02 Sep 2009, 07:50 AM
To come back on my own post. I finally found out what was causing the problem.
Setting the DataContext on the UserControl changed the level the Test property was binding to.

<GridItems:ActivityDetails DataContext="{Binding Monday}" Test="{Binding}" /> 

If the DataContext is set, the type that is bound to the Test property will be "SheduleActivity".

If the DataContext isn't set, the type that is bound to the Test property will be "SheduleWeek".

It's easy but you have to know it..
Tags
GridView
Asked by
Hans Notelteirs
Top achievements
Rank 1
Answers by
Hans Notelteirs
Top achievements
Rank 1
Share this question
or