User Id :    Password :      New Member   Forgot Password  
Assign ToolTip to dynamically created colum of silverlight Gridview
Description Assign ToolTip to dynamically created colum of silverlight Gridview and How to create style for element runtime   No. of Views     2247
  Rating     0
Author Pranay Rana   Posted On     13 Sep 2012
Tags C#,Silverlight,XAML    

Sample Code   Download Code

In this post I am going to discuss about displaying tooptip for autogenerated columns of toolkit silverlight and telerik silverlight gridcongtrol. Also goint to discuss about how to create style dynamically for the silverlight control.

How to create style in codebehind i.e. runtime for control To define the style sheet for any silverlight control on runtime there you need to do following things

1. Create Style object with the type of control


var style = new Style(typeof(controlType));


Control type can be Grid, GridviewCell, Textblock etc. i.e any valid silverlight control.

2. Add Setter to Created Style Object


style.Setters.Add(new Setter(StylePropertyName, Value));


You need to pass property name and value now after this, below discussion you will find example for the same

3. Attach Created Style to the control type object


controlboject.stylefor = style; 


Now following describe how to user the dynamic style and display tooltip for header of autogenerated columns of gridview.

To apply the style at runtime to autogetnerated column I made use of AutoGenerated Event of the grid in both of the below example.
Code for displaying tootip for Telerik grid


private void EditableGV_AutoGeneratingColumn
       (object sender, GridViewAutoGeneratingColumnEventArgs e)
   GridViewDataColumn column = e.Column as GridViewDataColumn;
   //for tooltip dispaly
   var style = new Style(typeof(GridViewHeaderCell));
   style.Setters.Add(new Setter(ToolTipService.ToolTipProperty,
   column.HeaderCellStyle = style;


As you see in above code Style is get created for the Headercell of grid view. ToolTip property style is added by using setting as we discuss above. Lastly assigned created style to headercell style.

Silverlight gridview
Same as Telerik gird,in tool grid I made use of Autogenerated column


private void dataGrid1_AutoGeneratingColumn
            (object sender, DataGridAutoGeneratingColumnEventArgs e)
  DataGridBoundColumn column = e.Column as DataGridBoundColumn;
  var style = new Style(typeof(DataGridColumnHeader));
  style.Setters.Add(new Setter(ToolTipService.ToolTipProperty,
  column.HeaderStyle = style;


Just few code difference , here style is created for headercell only but the name of the class is diffrerent, which you can notice easily by comparing both code.

About Author

About Author Hey, I am Pranay Rana, working as a Senior Software engineer. Web development in Asp.Net with C# and MS sql server are the experience tools that I have had for the past 5 years now.
For me def. of programming is : Programming is something that you do once and that get used by multiple for many years
You can visit me on my blog -
Pranay Rana
No Photo
Country India
Company GMind Solutions
Home Page

Rate this article

Rating options from poor, fair, good, very good to excelent.  


Write your comment here.
Verification Code