Click here to Skip to main content
12,294,372 members (60,643 online)
Click here to Skip to main content

Stats

295.4K views
4K downloads
263 bookmarked
Posted

WPF.JoshSmith

, 13 Jul 2008 CPOL
A free library of controls and utility classes for use in WPF applications.
WPF.JoshSmith
Resources
Images
Composers
bach.jpg
beethoven.jpg
chopin.jpg
handel.jpg
haydn.jpg
mozart.jpg
part.jpg
reich.jpg
scarlatti.jpg
schoenberg.jpg
Robots
colorful robot.jpg
reflected robot.jpg
Robot up close.jpg
Robot.jpg
space robot.jpg
Steelbot.jpg
Weird Robot.jpg
Wooden Robot.jpg
Test.CenteredContentControl
harpsichord.jpg
Properties
Test.DragCanvas
Images
girls.gif
Properties
Test.ListViewDragDropManager
Properties
Test.RegexValidator
Properties
Test.SlidingListBox
Properties
Test.SmartTextBox
Properties
Test.UnloadedManager
Properties
TestPages
Test.ValueConverterGroup
Properties
WPF.JoshSmith
Adorners
Controls
Utilities
Validation
Data
ValueConverters
Input
Markup
Panels
Properties
ServiceProviders
UI
bach.jpg
beethoven.jpg
chopin.jpg
handel.jpg
haydn.jpg
mozart.jpg
part.jpg
reich.jpg
scarlatti.jpg
schoenberg.jpg
colorful robot.jpg
reflected robot.jpg
Robot up close.jpg
Robot.jpg
space robot.jpg
Steelbot.jpg
Weird Robot.jpg
Wooden Robot.jpg
harpsichord.jpg
girls.gif
bach.jpg
beethoven.jpg
chopin.jpg
handel.jpg
haydn.jpg
mozart.jpg
part.jpg
reich.jpg
scarlatti.jpg
schoenberg.jpg
colorful robot.jpg
reflected robot.jpg
Robot up close.jpg
Robot.jpg
space robot.jpg
Steelbot.jpg
Weird Robot.jpg
Wooden Robot.jpg
harpsichord.jpg
girls.gif
<Window x:Class="Test.RegexValidator.RegexValidatorWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:jas="clr-namespace:WPF.JoshSmith.Controls.Validation;assembly=WPF.JoshSmith" 
    xmlns:local="clr-namespace:Test.RegexValidator" 
    Title="RegexValidator &amp; RegexValidationRule Test" Height="300" Width="375"
    FontSize="12"
    >
  <Window.Resources>
    <!-- This style allows a validation error message to be 
         displayed in a TextBox's tooltip. -->
    <Style TargetType="{x:Type TextBox}">
      <Setter Property="Margin" Value="0,8" />
      <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>
  </Window.Resources>
  
  <StackPanel Margin="4" VerticalAlignment="Center">
    <TextBlock>E-mail Address:</TextBlock>
    <TextBox 
      Text="{Binding Path=EmailAddress, UpdateSourceTrigger=PropertyChanged}" 
      jas:RegexValidator.RegexText="^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$" 
      jas:RegexValidator.ErrorMessage="Invalid e-mail address." 
      />

    <!-- Sets the RegexText attached property to a static property
         which returns a localized regex, for the current date format. -->
    <TextBlock>Localized Date:</TextBlock>
    <TextBox 
      Text="{Binding Path=DateString, UpdateSourceTrigger=PropertyChanged}" 
      jas:RegexValidator.RegexText="{x:Static local:DateFormatRegex.DateRegex}" 
      jas:RegexValidator.ErrorMessage="Invalid date format." 
      />

    <!-- Explicitly creates a RegexValidationRule in order to set the RegexOptions. -->
    <TextBlock>Product Code:</TextBlock>
    <TextBox>
      <TextBox.Text>
        <Binding Path="ProductCode" UpdateSourceTrigger="PropertyChanged">
          <Binding.ValidationRules>
            <jas:RegexValidationRule
              RegexText="^[A-Z]{3}\.[0-9]{3}$"
              ErrorMessage="Invalid product code.  (Examples: ABC.123  xyz.789)"
              RegexOptions="IgnoreCase"
              />
              </Binding.ValidationRules>
            </Binding>
      </TextBox.Text>
    </TextBox>    
  </StackPanel>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Josh Smith
Software Developer (Senior) Cynergy Systems
United States United States
Josh creates software, for iOS and Windows.

He works at Cynergy Systems as a Senior Experience Developer.

Read his iOS Programming for .NET Developers[^] book to learn how to write iPhone and iPad apps by leveraging your existing .NET skills.

Use his Master WPF[^] app on your iPhone to sharpen your WPF skills on the go.

Check out his Advanced MVVM[^] book.

Visit his WPF blog[^] or stop by his iOS blog[^].

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160525.2 | Last Updated 13 Jul 2008
Article Copyright 2006 by Josh Smith
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid