Silverlight: How to style the validation tooltip?

2019-04-28 11:49发布

问题:

I did some searching but it wasn't what I was looking for. So, does anyone know a way how to style the validation tooltip in Silverlight(the thing in the green border)?

alt text http://img689.imageshack.us/img689/222/validationtooltip.png

Any help would be greatly appreciated!

Best Regards,

~K

回答1:

Unfortunately you can't easily provide a style for the validation tooltip without effectively styling the entire Textbox control. Blend makes this fairly easy if you are familiar with using that design tool. However if your a dyed in the wool coder like me then...

  • Goto this page on MSDN TextBox Styles and Templates
  • Copy the vsm namespace alias to your UserControl xaml
  • Copy the TextBox style into UserControls.Resources give it at an x:Key name (say MyTextBoxStyle")
  • Copy the ValidationToolTipTemplate from the web page to the UserControls.Resources, paste it above the TextBox style. It already has an x:Key name that the TextBox style will be referencing.
  • Add Style="{StaticResource MyTextBoxStyle}" to your TextBox in the data grid.

Now you play around with the validation elements of the templates to get your desired result.



回答2:

The validation messages are displayed as a visual state. you can get to these (and edit them) as templates directly from blend.