I do some validation on the DataSource TextBox, which is inside the Expander, and find that after the validation error was triggered, if I hide the Expander, the red box will remain where the TextBox would be.
<Expander Header="Blah Blah Blah"> <TextBox Name="TextBox" Validation.ErrorTemplate="{DynamicResource TextBoxErrorTemplate}" Text="{Binding Path=Blah, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" /> </Expander>
I tried to get around this by associating the visibility of the error pattern with the extender, but I think something is wrong with the binding.
<local:NotVisibleConverter x:Key="NotVisibleConverter" /> <ControlTemplate x:Key="TextBoxErrorTemplate"> <DockPanel> <Border BorderBrush="Red" BorderThickness="2" Visibility="{Binding Path=IsExpanded, Converter={StaticResource NotVisibleConverter}, RelativeSource={RelativeSource AncestorType=Expander}}" > <AdornedElementPlaceholder Name="MyAdorner" /> </Border> </DockPanel> <ControlTemplate.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate>
I guess I did wrong with my binding, can someone get me back on track? Or does anyone know of another solution for ErrorTemplate that is still visible when Expander crashes?
validation wpf binding controltemplate
Andy Clarke Sep 24 '09 at 12:43 2009-09-24 12:43
source share