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

Exception when binding the tootip of the headers

12 Answers 165 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jose Simas
Top achievements
Rank 2
Jose Simas asked on 19 Apr 2011, 11:20 AM
Hi,

I think I found a bug while trying to set the tooltip for the headers. This seems to be a regression. I downloaded the code from this post:

http://www.telerik.com/community/forums/wpf/gridview/displaying-the-radgrid-header-column-tooltip.aspx

Converted the ColumnTooltip project in that post to VS 2010, changed the .NET framework version to 4.0 CP and replaced the telerik dlls with the latest version. I then run the sample and when I hover the mouse over a header the app crashes with the exception below. The tooltip is being set as in:

<Setter Property="ToolTip" Value="{Binding Content, RelativeSource={RelativeSource Self}}"/>

Did this change in later versions?

Here is the exception:
 
System.InvalidOperationException was unhandled
  Message=Specified element is already the logical child of another element. Disconnect it first.
  Source=PresentationFramework
  StackTrace:
       at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
       at System.Windows.FrameworkElement.AddLogicalChild(Object child)
       at System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
       at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
       at System.Windows.Controls.PopupControlService.RaiseToolTipOpeningEvent()
       at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run()
       at ColumnTooltip.App.Main() in E:\temp\ColumnTooltip\ColumnTooltip\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

12 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 19 Apr 2011, 12:27 PM
Hello Jose,

 

Indeed we are aware of such an issue related to the ToolTip set within a style targeted at GridViewHeaderCell.
As a kind of workaround you may define the Header by yourself and set the tooltip directly, as shown below:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" >
    <telerik:GridViewDataColumn.Header>
        <TextBlock Text="Name" ToolTip="I am ToolTip" />
    </telerik:GridViewDataColumn.Header>
</telerik:GridViewDataColumn>


Please excuse us for any inconvenience caused.

Kind regards,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jose Simas
Top achievements
Rank 2
answered on 19 Apr 2011, 12:30 PM
Hi,

I am afraid I cannot use this workaround because my GridView is bound to a DataTable and the columns are generated internally by the GridView. Is there any other way to solve this problem (even if not limited to XAML)?

Jose
0
Vlad
Telerik team
answered on 19 Apr 2011, 12:34 PM
Hi,

 You can set the column Header exactly in the same way in code as in XAML:

var column = new GridViewColumn();
column.Header = new TextBlock() { ToolTip = "Your tooltip" };

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jose Simas
Top achievements
Rank 2
answered on 19 Apr 2011, 05:51 PM
Hi Vanya,

This does not solve my problem because I don't create the columns myself. I could maybe iterate over them after they are created and replace the headers but before I do that I have a question:

Is this a bug that has been registered and will be fixed soon? I am asking this because I am not releasing this code for a while so I can wait for you next revision.

Cheers,
Jose
0
Vlad
Telerik team
answered on 20 Apr 2011, 06:40 AM
Hi Jose,

 I'm Vlad - not Vanya :)

Such binding is no longer supported since the grid internal structure (XAML templates) is not longer the same as back in 2008.

All the best,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jose Simas
Top achievements
Rank 2
answered on 20 Apr 2011, 08:37 AM
Hi Vlad,

I am terribly sorry about the name mixup.

So, if I understood correctly, it is not possible to set a tooltip for a column header when a grid is bound to a DataTable. Is this a feature you will add at some point?

Jose
0
Vlad
Telerik team
answered on 20 Apr 2011, 08:42 AM
Hi,

Actually you can. Please check both my and Vanya posts.

All the best,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jose Simas
Top achievements
Rank 2
answered on 20 Apr 2011, 08:57 AM
Hi,

I must be missing the point somewhere. So my grid definition in XAML is:

<telerik:RadGridView 
    ItemsSource="{Binding DatasetSelector.CurrentDataTable}"
    Margin="5,5,5,0"
    SelectionMode="Extended"
    ShowGroupPanel="False"
    IsReadOnly="True"
    ColumnWidth="SizeToCells"
    >
    <telerik:RadGridView.Resources>
        <Style TargetType="{x:Type telerik:GridViewCell}">
            <Style.Setters>
                <Setter Property="MinWidth" Value="65"/>
                <Setter Property="HorizontalContentAlignment" Value="Right"/>
            </Style.Setters>
        </Style>
    </telerik:RadGridView.Resources>
</telerik:RadGridView>

Where DatasetSelector.CurrentDataTable is a System.Data.DataTable. To add tooltips to all the column header I changed it to:

<telerik:RadGridView 
    ItemsSource="{Binding DatasetSelector.CurrentDataTable}"
    Margin="5,5,5,0"
    SelectionMode="Extended"
    ShowGroupPanel="False"
    IsReadOnly="True"
    ColumnWidth="SizeToCells"
    >
    <telerik:RadGridView.Resources>
        <Style TargetType="{x:Type telerik:GridViewCell}">
            <Style.Setters>
                <Setter Property="MinWidth" Value="65"/>
                <Setter Property="HorizontalContentAlignment" Value="Right"/>
            </Style.Setters>
        </Style>
        <Style TargetType="{x:Type telerik:GridViewHeaderCell}">
            <Style.Setters>
                <Setter Property="ToolTip" Value="{Binding Content, RelativeSource={RelativeSource Self}}"/>
            </Style.Setters>
        </Style>
    </telerik:RadGridView.Resources>
</telerik:RadGridView>

But it crashes with the exception I put in the first post.

Vanya's solution was to add the tooltip to the column definitions in XAML but since the grid structure is being generated automatically by the GridView there are no column definitions in the XAML. Your solution was to do the same in code but since I am not creating the structure myself (and I cannot do it without generating a class at runtime) I am stuck again.

So the question is: how can I add tootips to the headers of a GridView that is bound to a DataTable when AutoGenerateColumns is True.

Cheers,
Jose

0
Accepted
Vlad
Telerik team
answered on 20 Apr 2011, 09:01 AM
Hi,

To modify auto-generated column you can handle AutoGeneratingColumn event and use e.Column to modify/assign desired properties. For example:

e.Column.Header = new TextBlock() { Text = "Your text", ToolTip = "Your tooltip" }

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jose Simas
Top achievements
Rank 2
answered on 20 Apr 2011, 09:07 AM
Hi,

Great. That solves the problem.

Jose
0
Christoph
Top achievements
Rank 1
answered on 16 Nov 2011, 09:52 AM
The original thread topic (exception) applies to me as well in the current Q2 2011 release: I need a simple, static, tooltip for each header column.

Is this going to be fixed in Q3? (because it is rather laughable that doing something as simple as a header tooltip doesn't work)

Chris
0
Christoph
Top achievements
Rank 1
answered on 16 Nov 2011, 09:52 AM
The original thread topic (exception) applies to me as well in the current Q2 2011 release: I need a simple, static, tooltip for each header column.

Is this going to be fixed in Q3? (because it is rather laughable that doing something as simple as a header tooltip doesn't work)

Chris
Tags
GridView
Asked by
Jose Simas
Top achievements
Rank 2
Answers by
Vanya Pavlova
Telerik team
Jose Simas
Top achievements
Rank 2
Vlad
Telerik team
Christoph
Top achievements
Rank 1
Share this question
or