lunedì 17 giugno 2013

[WPF] Stile validazione campo TextBox

Da incollare nel file App.xaml

<Style TargetType="{x:Type TextBox}">
                <Setter Property="Validation.ErrorTemplate">
                    <Setter.Value>
                        <ControlTemplate>
                            <DockPanel LastChildFill="True">
                                <TextBlock DockPanel.Dock="Right" Foreground="Gray" Margin="2" FontSize="12pt" Text="*" />
                                <Border >
                                    <AdornedElementPlaceholder Name="MyAdorner" />
                                </Border>
                            </DockPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="Validation.HasError" Value="true">
                        <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors).CurrentItem.ErrorContent}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

Nessun commento:

Posta un commento