views:

13

answers:

1

Dear all,

I have a template column in a DataGrid:

 <sdk:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" >

                                    <TextBlock Text="{Binding Name,ElementName=rsAllSkills}"/>
                                </StackPanel>
                            </DataTemplate>
 </sdk:DataGridTemplateColumn.CellEditingTemplate>

And in the same xaml file, I have

<riaControls:DomainDataSource QueryName="GetSkillsQuery" AutoLoad="True" x:Name="rsAllSkills">
            <riaControls:DomainDataSource.DomainContext>
                <domain:XXXX context/>
            </riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>

The DataSource has loaded everything successfully for sure, if I put that TextBlock out side of the DataGrid, it works; but inside the DataGrid, it doesn't load even the Name of rsAllSkills....

Could anybody give me a hint, thank you so much.

A: 

Have a dummy converter and check the binding.

What I guess is, the DataTemplate inside the CellEditingTemplate would receive the parent's DataContext, ie., DataGrid's DataContext. So, to work around this you can do one thing.

1) Bind the rsAllSkills to the Tag Property of DataGridTemplateColumn.
2) Now, Bind the TextBlock's Text property with the Tag property like,

<sdk:DataGridTemplateColumn Tag="{Binding Name,ElementName=rsAllSkills}">
    <sdk:DataGridTemplateColumn.CellEditingTemplate>
         <DataTemplate>
              <StackPanel Orientation="Horizontal" VerticalAlignment="Center" >    
                  <TextBlock Text="{Binding Tag}"/>
              </StackPanel>         
         </DataTemplate>
    </sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>
Avatar
I solved this problem by defining the Ria data source control as a static resource... but I will give your solution a shot and mark as solution if it works. Thanks!
......it doesn't have Tag property...
@user299230 I guess, the static resource is the far best way. :)
Avatar