开发者

IDataErrorInfo Red Borders And TabItem Control

I have a user control that is binded to a view model and I use IDataErrorInfo for validations with the default red border indication in case of validation errors.

Here is one of my controls:

<TextBox Text="{Binding Path=Code, ValidatesOnDataErrors=True}"></TextBox>

Everything works fine and during initialization all controls that have validation errors have this red border visible. All except the controls that are inside a TabItem control that is not visible (not selected) during initialization. These controls don't display the red border although the validation runs fine also for them.

I isolated the problem and it is CLEARLY that the red border does not appear because the controls are not visible in the initial layout of the user control.

My question is do I miss somethin开发者_如何转开发g, and if not then how I can manually force validation for all my controls in the user control to run again so to display the red borders at least during TabControl.SelectionChanged?

Thank you in advance.


I found a workaround

I created a style where whenever IsVisible property of control is set to true I apply my own Validation.ErrorTemplate:

<Style TargetType="{x:Type TextBox}">
            <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"></Setter>
                        <Style.Triggers>
                                    <Trigger Property="IsVisible" Value="True">
                    <Setter Property="Validation.ErrorTemplate">
                        <Setter.Value>
                            <ControlTemplate>
                                <Border BorderBrush="Red" BorderThickness="1" >
                                    <AdornedElementPlaceholder/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜