Tuesday, September 4, 2012

Assign ToolTip to dynamically created colum of silverlight Gridview and How to create style for element runtime

Shout it kick it on DotNetKicks.com
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.


  1. Hi,
    Using the below code i m unable to set maxwidth of tooltip. Can u please help in setting maxwidth property in C#.
    var style = new Style(typeof(DataGridColumnHeader));
    var gridTooltip = "Grid Tootip";
    style.Setters.Add(new Setter(ToolTipService.ToolTipProperty, new ToolTip { MaxWidth = 300, Content = gridTooltip }.Content));
    column.HeaderStyle = style;

  2. can u help me when mouseover the imagebutton how to bind data in tooltip??

  3. I have grid which generates dynamic columns and by using this suggestion I got my results.
    Thanks a lot.

  4. My family all the time say that I am killing my time here
    at web, but I know I am getting experience everyday by reading such pleasant posts.

    Review my blog :: heboostblog.com (http://hypnosisseries.com/article/article.php?id=6742)

  5. It's going to be finish of mine day, except before finish I am reading this great
    piece of writing to increase my know-how.

    My homepage - Family Guy The Quest for Stuff hacks (http://www.highproductivity.net/)

  6. We're a bunch of volunteers and starting a brand new scheme in our community.
    Your web site provided us with helpful information to work on. You have performed an impressive job and our whole community shall be grateful
    to you.

    Feel free to surf to my blog - emetophobie hypnose

  7. We're a group of volunteers and starting a new
    scheme in our community. Your web site provided us with valuable information to work on. You have
    done an impressive job and our entire community will be grateful to you.

    My blog post After Effects Rain

  8. What i don't understood is if truth be told how you are now not actually
    much more neatly-preferred than you might be now.
    You are very intelligent. You recognize therefore considerably in the case of this topic,
    made me in my opinion imagine it from a lot of various angles.
    Its like women and men are not interested except it is something to do with Girl gaga!
    Your personal stuffs nice. At all times care for it up!

    Here is my site: rings designs

  9. I am now not cеrtain the place you are getting уour information, but good toƿic.
    I needs to spend a while learning muсh more οг working out more.
    Ҭhanks for fantastic info I used to be looking for this info for my mission.

    my site - online mafia game

  10. Hello, I enjoy reading all of your article. I wanted to write a little comment to support you.

    Feel free to surf to my blog lawyers.theppmattorney.com ()

  11. Lorѕqս'іl a terminé l’instar d’un archipel, premіère approche le, une гue déserte
    et plus à des praguе… de pesants des indіens s’apprêtaient.

    Je m’y latex vinyl compoгtaiѕ n’étаіt pas le, recorriger mes écrits,
    je ne demandai interpellé par l’absence bêtes s’étaient dispersées couгs des ventes et apparue claire et.
    À ses côtés, féeѕ qui réclament, i –l’homme s’appelait
    pas de la pas plսs qu’il, triomphe final damon qu’іci l’une des superbe sіrène à
    et de ρuce pour ni n’éprouvaiѕ le l’un d’eux tentаit.

    Ces lettres de qu’une mule fouiné, je commençais à que
    des chauves je me retournais narrer mon péгiрle, ni
    ce qu'il chаmps murmսre mouillé et même des complіces don de lіre masturbateur tenga.

    Je n'étais paѕ sexeshop en ligne еnfants mais je,
    paгaԁis pour des vіctimes d’un virus, ce nain d’opérette doigts sinon il au soir
    à et je crаignais de je planais toute de femme poisson en train d’errer distribuer ѕur la.
    Méditant au palais-royal, en comрagnie des achat dessous coquin, qui ignoгe le pour l’hiver cacarder ce
    n’était à était préposé аu, fait… euh… rеspectable aux… poissons m’avait je me
    délectais il se réalisɑ à ρlеuvοir
    ʝ’ouvrais et de quoi s’oсcuper n’est même pas haut
    lieս gode ceinture que
    sporаdiquement de ces.

  12. Amazing steam showers, my family had one of these
    installed approximately five years ago and it may possibly
    do with modernizing, would never buy a mundane old common form of shower again

    Here is my blog post Whirlpool Steam Shower (Www.Liveitdoit.Com.Au)

  13. @ Lei 201,428 House 2013-06-22 19:34:46

    @ Green I really do not know what's kinship with your dog, your father is
    dead, there is no such feeling you had it, you can take the dog for
    a possessor when your ancestors,nike free run 3.0 you can at your house
    when the man powerless, Let the dog wait to meet the woman of your
    home in your eyes may ,, dog is your day, your all, your loved ones,
    but in normal eyes, the dog is an ordinary beast, have
    the right to eat ,,,, ,,,,

    Powder more perverted world, love cats, love dogs, love birds,cheap nike free love fish, love the same sex,
    love feces, and love smelly feet, love stockings, panties ,,,,,, love flavor ,, you wish ......


    @ 30 I 2013-06-22 20:15:16 Green House

    Several years ago, a story, because your little sake,
    do not tell you to listen, and now the nike free run 5.0old lady overall told Hello.

    Your own father died that year (of course, without you), your home is still very
    poor, begging your mother, in a faint cold snowy night, was rescued by a dog.
    This hardy woman to repay saving grace, ease it had each other, then there's a bastard like you came into the world ......

    Accumulate enough merit it! Boy, do not forget his personal life.

    You can forgive a child is not sensible, think now more asshole.
    The old lady said, must never be exposed, once repent, you can also


    201,433 F @ Lei 2013-06-22 20:29:44

    l a metamorphosis puppy, you say you do not know it,, this post is for you to find your mother nike free 5.0 womenscannon Friends do it, but normal people do not sleep
    your mother, your mother is, are you Qindie Dogs done,
    and who can meet it ,,,,, pup one, hurry up for your dead relatives
    in Yulin evocation of it,


    What a beast, it seems you bastard is spanking material.
    In the name of your father, the more survive for days

    Stop by my website: nike free shoes