Hi all,
I think this is a simple question. I am using a validation approach as detailed here:
http://msdn.microsoft.com/en-us/library/ms752347.aspx#data_validation - where they use a ! colored Red with a tooltip to explain the error. It works just fine.
However, if I want to have a tooltip with the textbox (whatever), then that overrides the tooltip added by the validation routines.
How can I set up the validationTemplate ControlTemplate and/or textBoxInError Style so that the tooltip is preserved/restored/whatever when the error is correct? If that is not that easy, then I guess I would want to change the code so that the tooltip is on the red ! instead.'
Here is the base code for those of you leery about clicking on links:
in the resources section of the xaml document:
<ControlTemplate x:Key="validationTemplate"><DockPanel><TextBlock Foreground="Red" FontSize="20">!</TextBlock><AdornedElementPlaceholder /></DockPanel></ControlTemplate><!--<Setter Property="BorderBrush" Value="RoyalBlue" />--><Style x:Key="textBoxInError" TargetType="{x:Type TextBox}" BasedOn="{StaticResource crimestar-controls-textbox-dataentry}"><Style.Triggers><Trigger Property="Validation.HasError" Value="true"><Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}" /></Trigger></Style.Triggers></Style>
And the implementation of these is:
<TextBox Validation.ErrorTemplate="{StaticResource validationTemplate}" Style="{StaticResource textBoxInError}" ToolTip="Enter a description of what happened"><TextBox.Text><Binding Path="description" UpdateSourceTrigger="PropertyChanged"><Binding.ValidationRules><ExceptionValidationRule /><wpfMisc:dataRequired dataType="string" minLength="3" /></Binding.ValidationRules></Binding></TextBox.Text></TextBox>
Right now, even when there is an error, the tooltip on the textbox takes precidence. And I don't want to have to bind the tooltip to some property in the View model and then have that get updated when in an invalid state.
As you might notice from the commented out Green boarder setting - I am also trying to figure out how to change the textbox boarder to Red when an error condition exists.
All the examples I can find do this automatically (using <ExceptionValidationRule />) or only add the tooltip. I am sure there are some good examples, but they are not easy to find.
The other option I am currently trying to evaluate is using an IDataErrorInfo based approach. I am trying to avoid using any "code behind" the xaml file and only use xaml and the view model. But will look into this more over the next few days.
Thanks!
me (and yes, I DO mark correct answers)