Table of Contents
Accessing MaskedEdit Value

The value of an EO.Wpf MaskedEdit can be accessed either on the MaskedEdit control level, or on the MaskedEditSegment control level. Accessing the values on MaskedEditSegment level is more accurate and offers finer control, but accessing the value on the MaskedEdit is easier and more straight forward. This section explains both methods. You can choose either method based on your application requirement or personal preference.

Accessing Value on MaskedEditSegment Control

Since a MaskedEdit control can contain multiple MaskedEditSegment and each can be used to edit different type of values, accessing these values separately on each individual segment is both logical and straight forward. Consider the following MaskedEdit control used to enter a date value:

XAML
<eo:MaskedEdit x:Name="txtDate" PromptChar="_">
    <eo:NumericMaskedEditSegment x:Name="txtMonth" Digits="2" Minimum="1" Maximum="12" TabPattern="[/-]"></eo:NumericMaskedEditSegment>
    <eo:StaticMaskedEditSegment Text="/"></eo:StaticMaskedEditSegment>
    <eo:NumericMaskedEditSegment x:Name="txtDay" Digits="2" Minimum="1" Maximum="31" TabPattern="[/-]"></eo:NumericMaskedEditSegment>
    <eo:StaticMaskedEditSegment Text="/"></eo:StaticMaskedEditSegment>
    <eo:NumericMaskedEditSegment x:Name="txtYear" Digits="4" Minimum="2000" Maximum="2100" TabPattern="[/-]"></eo:NumericMaskedEditSegment>
</eo:MaskedEdit>

In this case, you can directly access each segment's Value directly:

//Get the year
int year = Convert.ToInt32(txtYear.Value);

//Get the month
int month = Convert.ToInt32(txtMonth.Value);

//Get the day
int day = Convert.ToInt32(txtDay.Value);

Note you can not directly cast the Value of a NumericMaskedEdigSegment to integer because:

  • The value maybe null. This is the case when user has not entered anything at all;
  • If user entered a value, then the value is Decimal. This is because a NumericMaskedEdigSegment also supports decimal digits (by setting Decimal to a value greater than zero);

You can also assign a value directly to the Value property to load a value into the segment. For example, the following code loads date 01/15/2013 into the MaskedEdit:

//Load 01/15/2013 into the MaskedEdit
txtYear.Value = 2013;
txtMonth.Value = 1;
txtDay.Value = 15;

Accessing Value on MaskedEdit Control

Alternatively, you can also access value directly on the MaskedEdit through its Text property. With the method you can only get the value as text. For example, with the above sample, you can use the following code to return the full date value as a string:

//This can return something like "01/15/2013"
string sDate = txtDate.Text;

You can also set the Text property to load a value into the MaskedEdit control. For example, the following code loads date "01/15/2013":

//Load date "01/15/2013"
txtDate.Text = "01/15/2013";