none
Blank or String.Empty string bind to tooltip showing small horizontal line on grid column

    Question

  • Hi,

    I am binding tooltip for grid column, but some time tooltip will be blank, at that time it is showing small horizontal line on mouse over  for that specific row on that column.

    Goal is:  if binded tooltip is blank or String .Empty than we do not want to collapas the visibility of tooltip.

    Can someone help me out to solve this issue?

    Thanks

    Bhushan Deshmukh

    Monday, February 06, 2012 5:28 AM

Answers

  • Hi Bhusha,

    You can bind the Visiblity of your tooltip to the same source as tooltip's content. Then use a converter to check if the content will be null and return Visibility.Visible or Visibility.Collapsed respectively.

    For details of how to use converter to control the visibility please refer to

    http://www.jeff.wilcox.name/2008/07/visibility-type-converter/

    Best Regards,

    Wednesday, February 08, 2012 6:17 AM
  • Hi Bhushan,

    Oh my mistake. Please modify it as follows.

    The general idea is to add a Rectangle on top of TextBlock and use Tooltip of Rectangle instead of TextBox. The visibilty of Rectangle is bound to the content of Tooltip as well and if tooltip is null, the rectangle will be hidden. Then the tooltip of Rectangle will not show either.

    <data:DataGridTemplateColumn Header="Name" HeaderStyle="{StaticResource CenterHeaderText}">
                 <data:DataGridTemplateColumn.CellTemplate>
                     <DataTemplate>

                        <Grid>
                        <TextBlock TextWrapping="Wrap" Text="{Binding Path=Name}"  VerticalAlignment="Stretch" Margin="3,3,0,0" MinHeight="26"></TextBlock>

                         <Rectangle Fill="Transparent" Visibility="{Binding Description, Converter={StaticResource converter}}" TooltipService.ToolTip="{Binding Description}" Margin="3,3,0,0"  />      

                         </Grid>           
                         </TextBlock>
                     </DataTemplate>
                 </data:DataGridTemplateColumn.CellTemplate>
             </data:DataGridTemplateColumn>

     

    Best Regards,

    Wednesday, February 29, 2012 1:38 AM

All replies

  • Hi Bhushan 

    Refer below thread it will help you to hide blank tooltip

    http://stackoverflow.com/questions/5910994/hide-tooltip-if-binding-is-null

    Regards

    David

    Smile

    Monday, February 06, 2012 5:55 AM
  • Hello David,

    I had tried following solution of given link but it is giving error

    Tried solution:

    <Style TargetType="ToolTip"> <Style.Triggers> <Trigger Property="Content" Value="{x:Static sys:String.Empty}"> <Setter Property="Visibility" Value="Collapsed" /> </Trigger> <Trigger Property="Content" Value="{x:Null}"> <Setter Property="Visibility" Value="Collapsed" /> </Trigger> </Style.Triggers> </Style>

    Error given:

    Error    1    The property 'Triggers' does not exist on the type 'Style' in the XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.  
    Error    2    The tag 'Trigger' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.    
    Error    3    The tag 'Trigger' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.    


    Please help me out on this.

    Thanks
    Bhushan




    Monday, February 06, 2012 7:44 AM
  • Hi Bhusha,

    You can bind the Visiblity of your tooltip to the same source as tooltip's content. Then use a converter to check if the content will be null and return Visibility.Visible or Visibility.Collapsed respectively.

    For details of how to use converter to control the visibility please refer to

    http://www.jeff.wilcox.name/2008/07/visibility-type-converter/

    Best Regards,

    Wednesday, February 08, 2012 6:17 AM
  • Hi,

    First thanks for your reply,

    I have tried you solution but still it is showing small horizontal line on mouse over  for that specific row on that column.

    For more your information check following screen shot (on line number 7) it will show clear understanding.

    https://skydrive.live.com/?sc=photos&cid=cd09dfbd30638bc0#cid=CD09DFBD30638BC0&id=CD09DFBD30638BC0%21151

    Can someone help me out to resolve this issue?

    Thanks

    Bhushan

    Thursday, February 09, 2012 12:33 AM
  • Hi,

    I am still waiting for solution.

    Is this silverlight grid tooltip issue?

    can someone help me out on this?

    Thanks

    Bhushan

    Tuesday, February 14, 2012 11:47 PM
  • Hi Bhushan,

    Please post related code here, then i will look into it and try to find the cause of this issue for you.

     

    Best Regards,

    Wednesday, February 15, 2012 12:04 AM
  • XAML code 
    -------------
    <data:DataGrid ItemsSource="{Binding ElementList}" Style="{StaticResource DetailsGridStyle}" MaxHeight="390" Name="dgElementList" SelectedItem="{Binding SelectedElementHelper, Mode=TwoWay}" HorizontalAlignment="Left" > <data:DataGrid.Columns> <data:DataGridTemplateColumn Header="Position" HeaderStyle="{StaticResource CenterHeaderText}"> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock TextWrapping="Wrap" Text="{Binding Path=OrdinalPosition}" VerticalAlignment="Stretch" Margin="3,3,0,0" MinHeight="26"/> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn> <data:DataGridTemplateColumn Header="Name" HeaderStyle="{StaticResource CenterHeaderText}"> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock TextWrapping="Wrap" Text="{Binding Path=Name}" VerticalAlignment="Stretch" Margin="3,3,0,0" MinHeight="26"> <ToolTipService.ToolTip> <TextBlock TextWrapping="Wrap" MinHeight="15" MaxWidth="300" Text="{Binding Path=Description}"></TextBlock> </ToolTipService.ToolTip> </TextBlock> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn> </data:DataGrid.Columns> </data:DataGrid> ------------------------------------------------------------------------------------------------------------------------
    CS file
    --------

    public ObservableCollection<Element> ElementList
            {
                get { return _elementList; }
                set
                {
                    _elementList = value;
                    RaisePropertyChanged("ElementList");
                }
            }


    Here is the code, please let me know if more information required from my side?

    Wednesday, February 15, 2012 11:49 PM
  • Hi Bhushan,

    Please try below code.

    <Usercontrol.Resource>

    <local:VisibilityConverter x:Key="converter" />

    </Usercontrol.Resource>

    ....

           <data:DataGridTemplateColumn Header="Name" HeaderStyle="{StaticResource CenterHeaderText}">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock TextWrapping="Wrap" Text="{Binding Path=Name}"  VerticalAlignment="Stretch" Margin="3,3,0,0" MinHeight="26">

                         <Rectangle Fill="Transparent" Visibility="{Binding Description, Converter={StaticResource converter}}" TooltipService.ToolTip="{Binding Description}"/>
                            <ToolTipService.ToolTip>                            
                                <TextBlock TextWrapping="Wrap" MinHeight="15"  MaxWidth="300" Text="{Binding Path=Description}"></TextBlock>                                                  
                            </ToolTipService.ToolTip>
                        </TextBlock>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

    VisibilityConverter .cs

    public class VisibilityConverter : IValueConverter
    {
        public object Convert(
            object value,
            Type targetType,
            object parameter,
            CultureInfo culture)
        {
            string visibility = (string)value;
            return visibility != null ? Visibility.Visible: Visibility.Collapsed;
        }
        public object ConvertBack(
            object value,
            Type targetType,
            object parameter,
            CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
     
    Please note above code is written by hand. Please correct any compile or logic error on your side.
     
    Best Regards,
    Friday, February 17, 2012 5:12 AM
  • Hi,

    I will try this and let you know, is it working or not?

    Thanks  Smile

    Bhushan

    Friday, February 17, 2012 10:19 PM
  • Hi Bhushan,

    How is your test resutl?

    Please let me know if this helps or if you are facing any problems.

     

    Best Regards,

    Monday, February 27, 2012 2:13 AM
  • Hi,

    Actually I am busy with other stuff for last week and this week. I will definetly let you know the result.

    Thanks

    Bhushan

    Monday, February 27, 2012 5:02 AM
  • Hi

    I have tried the solution but it is showing following errors.

    Error    3    The property 'ToolTip' does not exist on the type 'Rectangle' in the XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.  

    Error    4    The attachable property 'ToolTip' was not found in type 'TooltipService'.   

    Error    5    A value of type 'Rectangle' cannot be added to a collection or dictionary of type 'InlineCollection'.   


    Thanks

    Bhushan

    Wednesday, February 29, 2012 12:37 AM
  • Hi,

    I think 2 things are giving errorin the code

    1. Tooltip property is not present in the rectangle

    2. Rectangle property is not present under TextBlock

    <data:DataGridTemplateColumn Header="Name" HeaderStyle="{StaticResource CenterHeaderText}">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock TextWrapping="Wrap" Text="{Binding Path=Name}"  VerticalAlignment="Stretch" Margin="3,3,0,0" MinHeight="26">

                         <Rectangle Fill="Transparent" Visibility="{Binding Description, Converter={StaticResource converter}}" TooltipService.ToolTip="{Binding Description}"/>                
                        </TextBlock>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

    Thanks

    Bhushan

    Wednesday, February 29, 2012 12:58 AM
  • Hi Bhushan,

    Oh my mistake. Please modify it as follows.

    The general idea is to add a Rectangle on top of TextBlock and use Tooltip of Rectangle instead of TextBox. The visibilty of Rectangle is bound to the content of Tooltip as well and if tooltip is null, the rectangle will be hidden. Then the tooltip of Rectangle will not show either.

    <data:DataGridTemplateColumn Header="Name" HeaderStyle="{StaticResource CenterHeaderText}">
                 <data:DataGridTemplateColumn.CellTemplate>
                     <DataTemplate>

                        <Grid>
                        <TextBlock TextWrapping="Wrap" Text="{Binding Path=Name}"  VerticalAlignment="Stretch" Margin="3,3,0,0" MinHeight="26"></TextBlock>

                         <Rectangle Fill="Transparent" Visibility="{Binding Description, Converter={StaticResource converter}}" TooltipService.ToolTip="{Binding Description}" Margin="3,3,0,0"  />      

                         </Grid>           
                         </TextBlock>
                     </DataTemplate>
                 </data:DataGridTemplateColumn.CellTemplate>
             </data:DataGridTemplateColumn>

     

    Best Regards,

    Wednesday, February 29, 2012 1:38 AM
  • Hi,

    I think you have not notice the point's have writen.

    In the first point i have mention that "Tooltip property is not present in the rectangle" object.

    Still it is giving this error and Tooltip property is not present, then i think we have to find out another solution; I am not sure but still.

    I am waiting for your reply.

     

    Thanks

    Bhushan

    Wednesday, February 29, 2012 4:47 AM
  • Hi Bhushan,

    Oh i see.

    It should be  ToolTipService.ToolTip with the capital T.

    Please try again.

     

    Best Regards,

    Wednesday, February 29, 2012 9:32 PM
  • Hi,

    Now it is build successfully but giving runtime error

    Error : The property 'System.Windows.FrameworkTemplate.Template' is set more than once

    It is because of we are writing 2 objects (i.e. TextBlock and Rectangle) under <DataTemplate>.

    Thanks

    Bhushan

    Thursday, March 01, 2012 1:08 AM
  • Hi Bhushan,

    As my above code, please add a Grid wrapping outside TextBlock and Rectangle

    <DataTemplate>

                        <Grid>
                        <TextBlock TextWrapping="Wrap" Text="{Binding Path=Name}"  VerticalAlignment="Stretch" Margin="3,3,0,0" MinHeight="26"></TextBlock>

                         <Rectangle Fill="Transparent" Visibility="{Binding Description, Converter={StaticResource converter}}" TooltipService.ToolTip="{Binding Description}" Margin="3,3,0,0"  />     

                         </Grid>          
                     </DataTemplate>

     

    Best Regards,

    Thursday, March 01, 2012 1:14 AM
  • Hi,

    I am forgotten to write both the object under Grid.

    It is working fine.

    Thanks for you support. :)

    Smile

    Thanks

    Bhushan

    Thursday, March 01, 2012 1:14 AM