Version

Sections Property (XamMaskedEditor)

A collection of the sections used in the control. Returns a valid collection only if the mask has been parsed yet.
Syntax
'Declaration
 
Public ReadOnly Property Sections As SectionsCollection
public SectionsCollection Sections {get;}
Remarks

When mask is parsed the result is a collection of SectionBase derived objects. This property returns that collection. Each SectionBase object has a collection of its display characters return via its SectionBase.DisplayChars property. XamMaskedEditor also exposes a collection that contains aggregate display characters of all sections via its DisplayChars property.

This property is useful for example if you want to query and find out the structure of the parsed mask or to query and/or manipulate the current user input on a per section or per display character basis.

Example
The following code demonstrates Sections and DisplayChars property. It sets the Mask and Value properties and prints out the contents of the Sections collection and DisplayChars collection. The Mask and Value property both influence what the following will print out.

Private Sub Button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Me.maskedEditor1.StartEditMode()

        Me.maskedEditor1.Mask = "###-aaa"
        Me.maskedEditor1.Value = "123-XYZ"

        Dim sections As SectionsCollection = Me.maskedEditor1.Sections

        ' The follwing will print out sections. Sections are based on the 
        ' mask. The mask we set above has two edit sections and one 
        ' literal section.
        Debug.WriteLine("Sections: ")
        Debug.WriteLine("Sections(0) = " & sections(0).GetType().Name)
        Debug.WriteLine("Sections(1) = " & sections(1).GetType().Name)
        Debug.WriteLine("Sections(2) = " & sections(2).GetType().Name)

        ' Like sections, display characters are also based on mask.
        ' The following will print out all the display characters.
        ' It will print out the type of each display character and the
        ' character value associated with the display character (which
        ' comes from the Value that we set above).
        Debug.WriteLine("DisplayChars: ")
        Dim displayChars As DisplayCharsCollection = Me.maskedEditor1.DisplayChars
        Dim i As Integer
        For i = 0 To displayChars.Count - 1
            Dim dc As DisplayCharBase = displayChars(i)
            Debug.WriteLine("DisplayChars(" & i & ") = " & dc.GetType().Name & " '" & dc.Char & "'")
        Next
    End Sub
public void button1_Click( object sender, RoutedEventArgs e )
{
	this.maskedEditor1.StartEditMode( );

	this.maskedEditor1.Mask = "###-aaa";
	this.maskedEditor1.Value = "123-XYZ";

	SectionsCollection sections = this.maskedEditor1.Sections;

	// The follwing will print out sections. Sections are based on the 
	// mask. The mask we set above has two edit sections and one 
	// literal section.
	Debug.WriteLine( "Sections: " );
	Debug.WriteLine( "Sections[0] = " + sections[0].GetType( ).Name );
	Debug.WriteLine( "Sections[1] = " + sections[1].GetType( ).Name );
	Debug.WriteLine( "Sections[2] = " + sections[2].GetType( ).Name );

	// Like sections, display characters are also based on mask.
	// The following will print out all the display characters.
	// It will print out the type of each display character and the
	// character value associated with the display character (which
	// comes from the Value that we set above).
	Debug.WriteLine( "DisplayChars: " );
	DisplayCharsCollection displayChars = this.maskedEditor1.DisplayChars;
	for ( int i = 0; i < displayChars.Count; i++ )
	{
		DisplayCharBase dc = displayChars[i];
		Debug.WriteLine( "DisplayChars[" + i + "] = " + dc.GetType( ).Name + " '" + dc.Char + "'" );
	}
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also