Telerik blogs

In my previous blog post I explained how to display RadGridView Row Details with a RadWindow. Several days after the post was published I received a suggestion to create another sample that will be showing Row Details in a mouse-over tooltip fashion. And guess what. Christmas came earlier this year.

The full credit for coming up with this brilliant idea goes to my friend and colleague Kalin Milanov, our Front-end Developer. He decided to edit the GridViewRow ControlTemplate and removed the DetailsPresenter from the spot it usually occupies under the cells. He then placed it inside a ToolTip:

   1: <ToolTipService.ToolTip>
   2: <ToolTip Style="{StaticResource ToolTipStyle}" 
   3: Opened="OnToolTipOpened"
   4: Closed="OnToolTipClosed"> 
   5: <grid:DetailsPresenter 
   6: x:Name="PART_DetailsPresenter" 
   7: DetailsProvider="{Binding DetailsProvider, RelativeSource={RelativeSource TemplatedParent}}" 
   8: telerik:StyleManager.Theme="{StaticResource Theme}"/>
   9: </ToolTip>
  10: </ToolTipService.ToolTip>

There was a minor problem though. Row Details are collapsed, unless specified otherwise. So we attached to the Opened and Closed events of the ToolTip, found the respective GridViewRow and made its details Visible or Collapsed respectively:

   1: private void OnToolTipOpened(object sender, RoutedEventArgs e)
   2: {
   3:     GridViewRow parentRow = this.GetParentRow(sender);
   4:     parentRow.DetailsVisibility = Visibility.Visible;
   5: }
   7: private void OnToolTipClosed(object sender, RoutedEventArgs e)
   8: {
   9:     GridViewRow parentRow = this.GetParentRow(sender);
  10:     parentRow.DetailsVisibility = Visibility.Collapsed;
  11: }
  13: private GridViewRow GetParentRow(object sender)
  14: {
  15:     ToolTip toolTip = (ToolTip)sender;
  16:     Popup popup = (Popup)toolTip.Parent;
  17:     Club club = (Club)popup.DataContext;
  18:     GridViewRow parentRow = (GridViewRow)this.clubsGrid.ItemContainerGenerator.ContainerFromItem(club);
  19: return parentRow;
  20: }

Unfortunately, the ugly casting and searching above was inevitable. I wish the Owner property of the ToolTip class was public. Please, Microsoft, at least the getter. Anyway, here is what we got (it may take a while to load):


I just love ControlTemplates. Fabulous stuff.

You can get the full source code from here.

About the Author

Rossen Hristov

 is Senior Software Developer in Telerik XAML Team

Related Posts


Comments are disabled in preview mode.