Friday, November 8, 2013

ToolTip for Silverlight / WPF Controls

                Hi, in this article we are going to set tool tip for Silverlight / WPF control in XAML and code behind.

Setting Tool tip in XAML:

                To set tool tip in design time / XAML
                     <TextBlock MaxWidth="50"
                                Text="Binding Subject}"
                                TextTrimming="WordEllipsis"
                                ToolTipService.ToolTip="{Binding Subject}" />

                In the above example, the ToolTip is set by default for the text block control. If length of Subject exceeds the maximum length TextTrimming is enabled and word appears in trimmed format.

Setting Tool tip in Code Behind/ cs file:

                To create control in code behind and set TextTrimming and tool tip follow the steps,
     TextBlock txtBlock = new TextBlock();
     txtBlock.MaxWidth = 50;     
            txtBlock.Text = “MicroTechBlogger.blogspot.in”
            txtBlock.TextTrimming = TextTrimming.WordEllipsis;

            ToolTipService.SetToolTip(txtBlock, ColumnNames[controlCounter]);

No comments:

Post a Comment