Skip to main content

Microsoft Silverlight

Answered Question setting a tooltip on a DataGridTextColumn or instead using DataGridTemplateColumn but sorting doesn't workRSS Feed

(0)

silverbyte
silverbyte

Participant

Participant

1338 points

405 Posts

setting a tooltip on a DataGridTextColumn or instead using DataGridTemplateColumn but sorting doesn't work

Hello,

I have a DataGrid control with a column on which I want the sorting to work and also have a tooltip displayed on the cell.

I was unable to set  ToolTipService.ToolTip property on a DataGridTextColumn either directly or by using DataGridTextColumn.ElementStyle and then on TextBox.

I succeeded though to set it on a DataGridTemplateColumn but the sorting doesn't work.

Can you please tell me the right way to do this ?

Thank you.

 

Please click on 'Mark as answer' near my comment if you feel I answered your question.

silverbyte
silverbyte

Participant

Participant

1338 points

405 Posts

Re: setting a tooltip on a DataGridTextColumn or instead using DataGridTemplateColumn but sorting doesn't work

 Found the problem.

I need to set the SortMemberPath for any column not derived from DataGridBoundColumn,

But I still wonder how would one can set tool tips for a  DataGridTextColumn

Please click on 'Mark as answer' near my comment if you feel I answered your question.

Amanda Wang - MSFT
Amanda W...

All-Star

All-Star

17241 points

1,466 Posts

Answered Question

Re: setting a tooltip on a DataGridTextColumn or instead using DataGridTemplateColumn but sorting doesn't work

Hi,

silverbyte:
But I still wonder how would one can set tool tips for a  DataGridTextColumn

We have a test on our labs, if we set the Tooltip for the DataGridTextColumn, we got the error "Unknown attribute ToolTipService.ToolTip on element DataGridTextColumn". It is weird.

But if you want to add the tooltip for the DataGridColumn, you can try to use the DataGrid's DataGridTemplateColumn, and place a textBox in the template and set the TextBox's toolTip.

for example:

<data:DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
        <TextBox  Text="{Binding Lastname}"    ToolTipService.ToolTip="The LastName"  />
    </DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>

Amanda Wang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

silverbyte
silverbyte

Participant

Participant

1338 points

405 Posts

Re: Re: setting a tooltip on a DataGridTextColumn or instead using DataGridTemplateColumn but sorting doesn't work

 Yes, the same behaviour here, in the end I did replace it with a DataGridTemplateColumn but it's a pitty we need to do this just for the tooltip.

I guess this is a bug then ? Is there any complete list  with all known bugs in DataGrid or (better) in Silverlight 2 ?

 
Do you know if there is also a known problem with binding the Foreground property of DataGridTextColumn and using IValueConverter ?

In order not to discuss the same problem here please follow my thread regarding this: http://silverlight.net/forums/t/49800.aspx

Please click on 'Mark as answer' near my comment if you feel I answered your question.

Amanda Wang - MSFT
Amanda W...

All-Star

All-Star

17241 points

1,466 Posts

Re: Re: setting a tooltip on a DataGridTextColumn or instead using DataGridTemplateColumn but sorting doesn't work

Hi,

silverbyte:
I guess this is a bug then ? Is there any complete list  with all known bugs in DataGrid or (better) in Silverlight 2 ?
DataGridColumns aren’t actually visuals so setting a tooltip on them wouldn’t do anything.  You  can try to set the tooltip on the HeaderCell?  You can set that by styling it through the HeaderStyle.

Amanda Wang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

lawazia
lawazia

Member

Member

126 points

58 Posts

Re: Re: setting a tooltip on a DataGridTextColumn or instead using DataGridTemplateColumn but sorting doesn't work

You can create a custom datagrid column which supports tooltip as ahown here : 

public class DataGridTooltipColumn : DataGridTemplateColumn {

public string BindingExpression {

get { return ( string ) GetValue ( BindingExpressionProperty ); }

set { SetValue ( BindingExpressionProperty, value ); }

}

 

public static readonly DependencyProperty BindingExpressionProperty =

DependencyProperty.Register ( "BindingExpression", typeof ( string ), typeof ( DataGridTooltipColumn ), new PropertyMetadata ( new PropertyChangedCallback ( OnBindingExpressionChanged ) ) );

private static void OnBindingExpressionChanged ( DependencyObject d, DependencyPropertyChangedEventArgs e ) {

var dt = d as DataGridTooltipColumn;

if ( dt != null ) {dt.CellTemplate = dt.GetDataTemplate (e.NewValue as string);

}

}

private DataTemplate GetDataTemplate (string bindingExpression) {

return ( DataTemplate ) XamlReader.Load ( @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"">" +

@"<TextBlock Text=""{" + bindingExpression + @"}"" ToolTipService.ToolTip=""{" + bindingExpression + @"}"" />" +@"</DataTemplate>" );

}

}

 and use is this way :

<local:DataGridTooltipColumn Header="Ticket ID" BindingExpression="Binding Path=TicketId "/>

<local:DataGridTooltipColumn Header="ExpiryDate" BindingExpression="Binding Converter={StaticResource DateConverter} "/>

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities