开发者

Element Data-Binding in Silverlight

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 tha开发者_开发知识库t 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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜