I have a usercontrol and has a style to style all XamTextEditors in resources as such:
<UserControl.Resources> <ObjectDataProvider x:Key="dpContract" /> <Style TargetType="{x:Type igEditors:XamTextEditor}"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> </Style.Triggers> </Style> </UserControl.Resources>
The editor code:
<igEditors:XamTextEditor Grid.Row="0" Grid.Column="0" Theme="[current]" Name="xamTextEditorContractNo" HorizontalAlignment="Stretch" TextChanged="xamTextEditorContractNo_TextChanged" Text="{Binding Path=ContractNo, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" />
The tooltip is not showing up on validation error. If I give a key to style and set the style property in XamTextBox it works. Any ideas?
Using 9.2
Thanks
In WPF there is only 1 local style. If the Style property is set that is used as the local style. Otherwise WPF uses the first style it finds as it traverses the element and its ancestor's resources. When you set the Theme property of the control you are putting Styles into the control's Resources so that style ends up being the local style that WPF finds/uses which is why the one you have higher up the ancestor chain (i.e. in the UserControl's resources) is not being used. You need to either remove the Theme property setter or put the Style into the xamTextEditor's Resources which of course would prevent the Theme's Style from being used.
Well that makes sense. I thought it would be something in those lines. I guess I will have to set tool tip in code behind, instead of using triggers. Cause I want to be able to theme the control.
Is there a validation event I can handle to know after control called the IDataErrorInfo property method?
Or maybe I just create an event myself in my class that will be raised when property is invalid.
Hmm things to think about.
Anyways, thanks for your help with much appreciation.
Another way would be to create a custom multivalueconverter and bind the tooltip property. e.g.
For anyone who runs into this issue, this is what I ended up doing:
My texteditor:
<igEditors:XamTextEditor Grid.Row="0" Grid.Column="0" Theme="[current]" Name="xamTextEditorContractNo" HorizontalAlignment="Stretch" TextChanged="xamTextEditorContractNo_TextChanged" Validation.Error="xamTextEditorContractNo_Error" Text="{Binding Path=ContractNo, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
Notice the validation.error event and NotifyOnValidationError Property (took a while to figure I had to set that)
Then just handle the event in code.