MaskedCurrencyInput
The RadMaskedCurrencyInput represents the basic control that can be used to restrict the input of currency values.
In order to use the RadMaskedCurrencyInput control in your projects you have to add references to the following assemblies:
- Telerik.Windows.Controls
- Telerik.Windows.Controls.Input
You can find more info here.
Declaratively defined MaskedCurrencyInput
Here is a simple definition of a RadMaskedCurrencyInput control:
Example 1: Define RadMaskedCurrencyInput in XAML
<telerik:RadMaskedCurrencyInput Width="200"
Margin="20 20 20 10"
Culture="en-US"
EmptyContent="Enter digits"
InputBehavior="Replace"
Mask="#9.2"
SelectionOnFocus="SelectAll"
TextMode="PlainText"
UpdateValueEvent="LostFocus"
Value="12345.67" />
You can further customize the RadMaskedCurrencyInput control's behavior by setting the IsCurrencySymbolVisible property to False thus hiding the culture specific currency symbol. By default this property is set to True.
Properties
- Value: A property of type decimal? that gets or set the current value of the control.
- AutoFillNumberGroupSeparators: A boolean property that gets or sets whether number group separators are auto filled in the mask.
- AutoFillZeros: A boolean property that gets or sets whether trailing zeros should be auto filled.
- AllowSkipPlaceholders: A boolean property that gets or sets whether input can skip placeholders.
- IsCurrencySymbolVisible: A boolean property that gets or sets whether the currency symbol is visible or not. Default value is True.
Data Binding
RadMaskedCurrencyInput's Value property is of type nullable decimal (decimal?) and you have to bind it to ViewModel's property of type decimal or nullable decimal (if you need to set null).
Binding to object is not support and may result in unpredictable behavior.
Example 2: Define the view model
public class ViewModel : ViewModelBase
{
private decimal? amount;
public ViewModel()
{
this.Amount = 12345.67;
}
public decimal? Amount
{
get { return this.amount; }
set
{
if(this.amount != value)
{
this.amount = value;
this.OnPropertyChanged("Amount");
}
}
}
}
Example 3: Binding the Value property
<telerik:RadMaskedCurrencyInput Culture="en-US"
InputBehavior="Replace"
Mask="#9.2"
TextMode="PlainText"
UpdateValueEvent="LostFocus"
Value="{Binding Amount,Mode=TwoWay}" />
FormatString
You can further format the entered value by setting the FormatString property. It uses Standard Numeric Format Strings and Custom Numeric Format Strings to further format the Text property.
FormatString with Mask
When Mask property is set the FormatString property will be applied to the Text property of MaskedCurrencyInput control.
Example 4: Setting the FormatString property in Mask scenario
<telerik:RadMaskedCurrencyInput Culture="en-US" x:Name="currencyInput" Width="200"
EmptyContent="Enter digits"
FormatString="n3"
Mask="#9.2"
TextMode="PlainText"
UpdateValueEvent="PropertyChanged"
Value="12345.56" />
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text is: "/>
<TextBlock Text="{Binding Text,ElementName=currencyInput}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Value is: "/>
<TextBlock Text="{Binding Value,ElementName=currencyInput}"/>
</StackPanel>
</StackPanel>
FormatString with No-Mask
In No-Mask scenario the FormatString property will be applied to the Value property of MaskedNumericInput control.
Example 5: Setting the FormatString property
<telerik:RadMaskedCurrencyInput HorizontalAlignment="Center"
EmptyContent="Enter currency"
Culture="en-US"
FormatString="n3"
UpdateValueEvent="LostFocus"
SpinMode="PositionAndValue"
Value="123456"/>