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

Problem defining a tool-tip in a CellStyle

4 Answers 191 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 03 Dec 2013, 02:42 PM
Good morning,
I am having a problem when using an in-line CellStyle to set a 'condiitonal' ToolTip. The scenario I'm dealing with boils down to a single column where some rows have a tool-tip and others do not. Initially when hovering over a cell with a tool-tip the tool-tip is displayed correctly. I then hover over a cell without a tool-tip and as expected no tool-tip is displayed; however, upon returning to a cell with a tool-tip the tool-tip is no longer displayed correctly. If you repeat the process the tool-tip will alternate between working and not working. Why are the rows with a tool-tip being affected by the rows without? Thanks in advance!

We are currently on the 2013.2 Telerik libraries.

Below is a code sample that illustrates the problem. First is the ViewModel that holds a simple collection of Model objects.

using System.Collections.ObjectModel;
using System.Windows;
 
namespace ConditionalColumnToolTip
{
    public class ViewModel
    {
        public ViewModel()
        {
            Models = new ObservableCollection<Model>
                {
                    new Model{ Name = "HasAToolTip", ToolTipVisibility = Visibility.Visible, ToolTipText = "tool tip text"},
                    new Model{ Name = "HasAToolTip", ToolTipVisibility = Visibility.Visible, ToolTipText = "tool tip text"},
                    new Model{ Name = "NoToolTip", ToolTipVisibility = Visibility.Collapsed },
                    new Model{ Name = "HasAToolTip", ToolTipVisibility = Visibility.Visible, ToolTipText = "tool tip text"},
                };
        }
 
        public ObservableCollection<Model> Models
        {
            get; set;
        }
    }
}

Next is the simple definition of the Model object.

using System.Windows;
 
namespace ConditionalColumnToolTip
{
    public class Model
    {
        public string Name
        {
            get; set;
        }
 
        public Visibility ToolTipVisibility
        {
            get; set;
        }
 
        public string ToolTipText
        {
            get; set;
        }
    }
}

I set the DataContext of my MainWindow.xaml to an instance of the ViewModel in the MainWindow.xaml.cs

using System.Windows;
 
namespace ConditionalColumnToolTip
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
            DataContext = new ViewModel();
        }
    }
}


And finally here is the XAML for the MainWindow.xaml that recreates the issue.

<Window x:Class="ConditionalColumnToolTip.MainWindow"
        xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
        xmlns:vm="clr-namespace:ConditionalColumnToolTip"
        xmlns:gridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"
        Title="MainWindow" Height="350" Width="525"
        mc:Ignorable="d" d:DataContext="{d:DesignInstance vm:ViewModel, IsDesignTimeCreatable=True}">
    <Grid>
         
        <telerik:RadGridView ItemsSource="{Binding Models}" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                 
                <telerik:GridViewDataColumn Header="TITLE" DataMemberBinding="{Binding Name}">
                    <telerik:GridViewColumn.CellStyle>
                         
                        <Style TargetType="{x:Type gridView:GridViewCell}" BasedOn="{StaticResource {x:Type gridView:GridViewCell}}">
                            <Setter Property="ToolTip">
                                <Setter.Value>
                                    <ToolTip Visibility="{Binding ToolTipVisibility}">
                                        <TextBlock Text="{Binding ToolTipText}"/>
                                    </ToolTip>
                                </Setter.Value>
                            </Setter>
                        </Style>
                         
                    </telerik:GridViewColumn.CellStyle>
                </telerik:GridViewDataColumn>
                 
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
         
    </Grid>
</Window>

Any ideas would be greatly appreciated. Thanks again!

Cheers!

Jason

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 05 Dec 2013, 04:01 PM
Hello,

I have attached a project with a sample implementation. I hope it will give you some ideas.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jason
Top achievements
Rank 1
answered on 05 Dec 2013, 04:19 PM
Hi Didie,
Thanks for the reply! Unfortunately in your example tool-tips do not function at all, at least I am never getting a tool-tip on any cell regardless of how long I hover over the cell. Binding the ToolTipService.ToolTip property instead of the ToolTip property results in the exact same incorrect behavior. ToolTip is merely as pass through property based on the definition of FrameworkElement.cs

I apologize if my original post wasn't clear. My issue is when a single column has some cells with a tool-tip and some cells without. Initially hovering over a cell with a tool-tip will work correctly (attached image #1 from original post). If I then hover over a cell without a tool-tip the tool-tip is not displayed as expected (attached image #2 from original post); however, if I return to a cell with a tool-tip and hover over the cell the tool-tip bubble is displayed but the value within the tool-tip is not displayed correctly (attached image #3 from original post). I'm not seeing the same issue using other controls.

Defining the tool-tip via the cell style is strongly preferred due to the structure of our applications.Thanks again for your help in this matter,
Jason
.
0
Dimitrina
Telerik team
answered on 05 Dec 2013, 04:23 PM
Hi Jason,

You need to reduce the Width of the column, so that the displayed text to be not fully visible.
The demo illustrates how you could conditionally show a ToolTip.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jason
Top achievements
Rank 1
answered on 05 Dec 2013, 04:37 PM
Ok, now I see the code behind and get the tool-tip when shortening the column but this example doesn't reflect my scenario.

In my scenario the Visibility of the tool-tip is based on data in the Model object each row is bound to, not control or UI properties, thus the binding in the style. Our styles are used across many views and on potentially on multiple columns in each view so adding code behind to each view for each column tool-tip Visibility needs to be handled on is not a realistic option.Thanks,
Tags
GridView
Asked by
Jason
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Jason
Top achievements
Rank 1
Share this question
or