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

get parent datacontext from datatemplate

1 Answer 133 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bkerby
Top achievements
Rank 1
Bkerby asked on 22 Jun 2012, 07:11 PM
The textblock inside the tooltip can't find my viewmodel while the one bound to StatusText works fine.  How can i point ErrorText to use the datacontext of it's parent?

<telerik:GridViewDataColumn Header="Status" IsReadOnly="True" >
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding StatusText}" >
                                <ToolTipService.ToolTip>
                                    <ToolTip>
                                        <ToolTip.ContentTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding ErrorText}" Foreground="{Binding StatusForeColor}"/>
                                            </DataTemplate>
                                        </ToolTip.ContentTemplate>
                                    </ToolTip>
                                </ToolTipService.ToolTip>
                            </TextBlock> 
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 26 Jun 2012, 06:02 AM
Hello,

 You could specify the Source property of the Binding to be the ViewModel where the ErrorText is defined. For example:

<ToolTipService.ToolTip>
                                   <ToolTip>
                                       <ToolTip.ContentTemplate>
                                           <DataTemplate>
                                               <TextBlock Text="{Binding ErrorText, Source={StaticResource MyViewModel}, Mode=TwoWay}"/>
                                           </DataTemplate>
                                       </ToolTip.ContentTemplate>
                                   </ToolTip>
                               </ToolTipService.ToolTip>

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Bkerby
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or