Home Forums WPF controls Xceed DataGrid for WPF Tooltips and Blank Data

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24455 |

    We have added a ToolTip like this:

    <Style TargetType=”{x:Type xcdg:DataCell}”>
    <Setter Property=”ToolTip”
    Value=”{Binding RelativeSource={RelativeSource Self}, Path=Content}”/>
    </Style>

    This works great and we defined also our own custom Style.

    <Style TargetType=”{x:Type ToolTip}”>
    <Setter Property=”Template”>
    <Setter.Value>
    <ControlTemplate TargetType=”{x:Type ToolTip}”>
    <Border x:Name=”Border” Margin=”10,10,10,10″ Padding=”10,2,10,2″
    BorderBrush=”#FF9A9A9A” BorderThickness=”1,1,1,1″
    Background=”{DynamicResource LinearGradient}” >

    <Border.BitmapEffect>
    <OuterGlowBitmapEffect GlowColor=”#FF000000″ GlowSize=”10″ Opacity=”0.3″/>
    </Border.BitmapEffect>

    <ContentPresenter x:Name=”theContent”
    Content=”{TemplateBinding ToolTip.Content}”/>
    </Border>

    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>

    This works great. Except that one of our Columns can have blank data (it’s a DateTime). What happens then is there a square blank ToolTip (because of the Margin and Padding).

    How do we not show a ToolTip if there is no Content in the ContentPresenter?

    We tried this (and things similar to this):

    <ControlTemplate.Triggers>
    <Trigger Property=”Content” Value=”” SourceName=”theContent”>
    <Setter Property=”Visibility” Value=”Collapsed” TargetName=”Border”/>
    </Trigger>
    </ControlTemplate.Triggers>

    However, it does not work. So we were wondering how to do what we want?

    Thanks

    Imported from legacy forums. Posted by Mark (had 670 views)

    User (Old forums)
    Member
    Post count: 23064

    Any thoughts? It would be really nice to not have tooltips come up when there is no data in that cell. Also, we were thinking it would be cool to only show tooltips when you have elispses (dot dot dot or …).

    Thanks

    Imported from legacy forums. Posted by Mark (had 351 views)

    User (Old forums)
    Member
    Post count: 23064

    Try to bind the Visibility to the Width of the Cell’s content.

    Imported from legacy forums. Posted by Lena (had 397 views)

    User (Old forums)
    Member
    Post count: 23064

    That lead us down the right path! Thanks! But the problem with using the width property is that it’s not set nor is the ActualWidth…. What we ended up doing is binding the Visibility to the Content property via a IValueConverter. Here is all our code:

    XAML:
    <Style TargetType=”{x:Type xcdg:DataCell}”>

    <Setter Property=”ToolTip” Value=”{Binding RelativeSource={RelativeSource Self}, Path=Content}”/>
    <Setter Property=”ToolTipService.InitialShowDelay” Value=”999″/>
    </Style>

    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    <xcdg:DataGridControl.Resources>
    <raedius:BlankContentToVisibilityConverter x:Key=”VisConverter”/>

    <Style TargetType=”{x:Type xcdg:TableViewScrollViewer}”>
    <EventSetter Event=”ScrollChanged” Handler=”ScrollChanged”/>
    </Style>

    <Style TargetType=”{x:Type ToolTip}”>
    <Setter Property=”Template”>
    <Setter.Value>
    <ControlTemplate TargetType=”{x:Type ToolTip}”>
    <Border x:Name=”theBorder” Visibility=”{Binding ElementName=theContent,
    Path=Content, Converter={StaticResource VisConverter}}”
    Margin=”10,10,10,10″ Padding=”8,1,8,2″ SnapsToDevicePixels=”True”
    BorderBrush=”#FF9A9A9A” BorderThickness=”1,1,1,1″
    Background=”{DynamicResource RaediusLinearGradient}” >
    <Border.BitmapEffect>
    <OuterGlowBitmapEffect GlowColor=”#FF000000″ GlowSize=”10″
    Opacity=”0.3″/>
    </Border.BitmapEffect>
    <ContentPresenter x:Name=”theContent” Content=”{TemplateBinding
    ToolTip.Content}”/>
    </Border>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    </xcdg:DataGridControl.Resources>

    The key to all this is:
    Visibility=”{Binding ElementName=theContent, Path=Content, Converter={StaticResource VisConverter}}

    Then you need this in Code Behind somewhere:
    public class BlankContentToVisibilityConverter : IValueConverter
    {
    public object Convert(object value, System.Type targetType, object parameter,
    System.Globalization.CultureInfo culture)
    {
    DateTime? theDateTime = null;
    string theString = null;
    int theInt = -1;

    //What is the type? Date or String or int?
    if (value != null && (value is String))
    theString = (String)value;

    else if (value != null && (value is DateTime))
    theDateTime = (DateTime)value;

    else if (value != null && (value is Int32))
    theInt = (Int32)value;

    //Set Visibility
    if (!String.IsNullOrEmpty(theString) || (theDateTime != null
    && ((DateTime)theDateTime).CompareTo(new DateTime()) != 0 )
    || theInt >= 0)
    return Visibility.Visible;
    else
    return Visibility.Collapsed;
    }

    /// <summary>
    /// Don’t need this for anything right now.
    /// </summary>
    public object ConvertBack(object value, System.Type targetType, object parameter,
    System.Globalization.CultureInfo culture)
    {
    return null;
    }
    }

    Seems like alot of work for getting the blank tooltip (with a custom style…) to go away when there is no data in the highlighted cell.

    Oh well, it works… And that’s all we care about. Thanks, again!

    Imported from legacy forums. Posted by Mark (had 3961 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.