locked
Dynamic tooltips inside datagrid columns RRS feed

  • Question

  • I have a datagrid that is using DataGridTemplateColumns.  Within each control, I want to be able to have a tool tip dynamically set.  For example, I want to put a tool tip for each cell in an editable datagrid that shows the default value when the row was added.  I can add a field to the object that is bound for each row but how do I get that value into the tool tip?  I tried binding to it and Silverlight yelled at me.

     Thanks in advance,

     Todd

    Thursday, March 26, 2009 2:19 PM

Answers

  •  If you want tooltip display string, use code below

            <data:DataGrid ItemsSource="{StaticResource provider1}">
                <data:DataGrid.Columns>
                    <data:DataGridTemplateColumn>
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Grid ToolTipService.ToolTip="{Binding Notes}">
                                    <TextBlock Text="{Binding Name}"/>
                                </Grid>
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                    </data:DataGridTemplateColumn>
                </data:DataGrid.Columns>
            </data:DataGrid>

     Data class definition

        public class Task 
        {
            public string Name { set; get; }
            public string Task { set; get; }
        }
    Wednesday, April 1, 2009 2:45 AM