get parent datacontext from datatemplate

2 posts, 0 answers
  1. Bkerby
    Bkerby avatar
    9 posts
    Member since:
    Apr 2012

    Posted 22 Jun 2012 Link to this post

    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>
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 26 Jun 2012 Link to this post

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

Back to Top