Exception when binding the tootip of the headers

13 posts, 1 answers
  1. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 19 Apr 2011 Link to this post

    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: 

  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 19 Apr 2011 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 19 Apr 2011 Link to this post

    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
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 19 Apr 2011 Link to this post

    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
  6. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 19 Apr 2011 Link to this post

    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
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 20 Apr 2011 Link to this post

    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
  8. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 20 Apr 2011 Link to this post

    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
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 20 Apr 2011 Link to this post

    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
  10. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 20 Apr 2011 Link to this post

    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

  11. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 20 Apr 2011 Link to this post

    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
  12. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 20 Apr 2011 Link to this post

    Hi,

    Great. That solves the problem.

    Jose
  13. Christoph
    Christoph avatar
    19 posts
    Member since:
    Apr 2008

    Posted 16 Nov 2011 Link to this post

    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
  14. Christoph
    Christoph avatar
    19 posts
    Member since:
    Apr 2008

    Posted 16 Nov 2011 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready