Click here to Skip to main content
15,891,253 members
Articles / Desktop Programming / WPF

WPF TextBox with PreviewTextChanged event for filtering

Rate me:
Please Sign up or sign in to vote.
4.60/5 (3 votes)
2 Aug 2011CPOL3 min read 47.6K   2.1K   9  
A WPF control, PreviewTextBox, used to filter/validate user input.
// Copyright © Transeric Solutions 2011.  All rights reserved.
// Licensed under Code Project Open License (see http://www.codeproject.com/info/cpol10.aspx).
// Author: Eric David Lynch.
using System;

namespace Extended.Windows.Controls
{
    /// <summary>
    /// An enumeration of possible change types.
    /// </summary>
    public enum TextChangedType
    {
        /// <summary>
        /// An assignment to the Text property.
        /// </summary>
        /// <remarks>
        /// Not currently supported.
        /// </remarks>
        Assign,
        /// <summary>
        /// A deletion of characters initiated by the user interface.
        /// </summary>
        Delete,
        /// <summary>
        /// An insertion of characters initiated by the user interface.
        /// </summary>
        Insert,
        /// <summary>
        /// A replacement of characters initiated by the user interface.
        /// </summary>
        Replace,
        /// <summary>
        /// An Undo command is changing the text.
        /// </summary>
        /// <remarks>
        /// Not supported by default.  Messy support is available via the PreviewUndoEnabled property.
        /// </remarks>
        Undo,
        /// <summary>
        /// A Redo command is changing the text.
        /// </summary>
        /// <remarks>
        /// Not supported by default.  Messy support is available via the PreviewUndoEnabled property.
        /// </remarks>
        Redo
    }
}

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)


Written By
Software Developer (Senior)
United States United States
Eric is a Senior Software Engineer with 30+ years of experience working with enterprise systems, both in the US and internationally. Over the years, he’s worked for a number of Fortune 500 companies (current and past), including Thomson Reuters, Verizon, MCI WorldCom, Unidata Incorporated, Digital Equipment Corporation, and IBM. While working for Northeastern University, he received co-author credit for six papers published in the Journal of Chemical Physics. Currently, he’s enjoying a little time off to work on some of his own software projects, explore new technologies, travel, and write the occasional article for CodeProject or ContentLab.

Comments and Discussions