Saturday, 15 August 2015

wpf controls - Common Tooltip style in WPF -


Can I create a tooltip style that can be applied to all tooltips for every control.

I tried it

  style target type = "{x: type tooltip}" & gt; & Lt; Setter Property = "Override Default Style" Value = "Correct" /> & Lt; Setter Property = "HesdropShadow" value = "true" /> & Lt; Setter Property = "Foreground" Value = "White" /> & Lt; Setter property = "font size" value = "12" /> & Lt; Setter Property = "Placement" Value = "Down" /> & Lt; Setter property = "workspace offset" value = "0" /> & Lt; Setter property = "padding" value = "8" /> & Lt; Setter property = "horizontal content alignment" value = "center" /> & Lt; Setter Estates = "Template" & gt; & Lt; Setter.Value & gt; & Lt; ControlTemplate TargetType = "{x: type tooltip}" & gt; & Lt; Stackpayel margin = "7,1" & gt; & Lt; Border background = "#FFF7F7cc" cornerRadia = "1" & gt; & Lt; TextBlock margin = "1" foreground = "black" horizontal alignment = "center" vertical alignment = "top" text = "{TemplateBinding ToolTip}" /> & Lt; / Border & gt; & Lt; / StackPanel & gt; & Lt; / ControlTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt;   

To use this style, I have put a different tooltip tag in control, for example to apply the tooltip to the limit

  & Lt; Border & gt; & Lt; Border.ToolTip & gt; & Lt; Tooltip Tooltip = "This is Tooltip Text" /> & Lt; /Border.ToolTip> ........... ......... & lt; / Border & gt;   

But there is no way where Tooltipstyle applies to all controls with the given tooltip given in the same tag. like. & lt; Border border brushes = "transparent" background = "transparent" cursor = "help" tooltip = "this is tooltip" & gt; ..... ..... & lt; / Border>

Tell me if any further information is needed or not. Thanks in anticipation.

Yes your approach will work but a small change is needed in the control template. Change the text block with ContentPresenter.

  & amp; the lift; ControlTemplate TargetType = "{x: type tooltip}" & gt; & Lt; Stackpayel margin = "7,1" & gt; & Lt; Border background = "#FFF7F7cc" cornerRadia = "1" & gt; & Lt; ContentPresenter margin = "1" horizontal alignment = "center" vertical alignment = "top" /> & Lt; / Border & gt; & Lt; / StackPanel & gt; & Lt; / ControlTemplate & gt;    

No comments:

Post a Comment