Prüft ob der eingegebene String, via RegEx, eine eMailadresse ist und gibt einen Bruh oder null zurück. Diesen Brush habe ich dann dazu benutzt einen grünen Haken zu zeichnen

emailvalidate

EmailValidationConverter:

1
2
3
4
5
6
7
8
9
10
11
12
13
public class EmailValidationConverter : IValueConverter
{
  #region IValueConverter Members
  public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  {
    return Regex.IsMatch(value.ToString(), @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w{2,6}$") ? Brushes.Green : null;
  }
  public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  {
    return value;
  }
  #endregion
}

Xaml:

1
2
3
<Window.Resources>
    <Converters:EmailValidationConverter x:Key="ValidateEMail" />
</Window.Resources>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<StackPanel Height="30" Orientation="Horizontal">
    <TextBox Width="100" Name="txtBoxValidateEMail" VerticalAlignment="Center" />
    <Grid>
        <Path HorizontalAlignment="Left" Margin="0,13,0,0" VerticalAlignment="Top" Width="14.21" Height="14.496" Stretch="Fill" Stroke="{Binding Text, ElementName=txtBoxValidateEMail, Mode=OneWay, Converter={StaticResource ValidateEMail}}" StrokeThickness="2" Data="M190,201 L210,203" RenderTransformOrigin="0.5,0.5">
            <Path.RenderTransform>
                <TransformGroup>
                    <ScaleTransform ScaleX="1" ScaleY="1"/>
                    <SkewTransform AngleX="0" AngleY="0"/>
                    <RotateTransform Angle="10"/>
                    <TranslateTransform X="0" Y="0"/>
                </TransformGroup>
            </Path.RenderTransform>
        </Path>
        <Path HorizontalAlignment="Left" Margin="9,-5,0,0" VerticalAlignment="Top" Width="14" Height="33" Stroke="{Binding Text, ElementName=txtBoxValidateEMail, Mode=OneWay, Converter={StaticResource ValidateEMail}}" Stretch="Fill" StrokeThickness="2" Data="M190,201 L222,169" RenderTransformOrigin="0.5,0.5">
            <Path.RenderTransform>
                <TransformGroup>
                    <ScaleTransform ScaleX="1" ScaleY="1"/>
                    <SkewTransform AngleX="0" AngleY="0"/>
                    <RotateTransform Angle="-5"/>
                    <TranslateTransform X="0" Y="0"/>
                </TransformGroup>
            </Path.RenderTransform>
        </Path>
    </Grid>
</StackPanel>
EMailValidationConverter – WPF Quicky
Markiert in: