Hello,
i have any Problems with the MaskedInput Control.
Scenario 1:
Validation Error Messages not showed by Application Start.
My Custom ControlTemplate for Validation.ErrorTemplate is showed,
but the ErrorMessage is Empty. This is a little bit funny.
You can see the Validation Methods in my TestModel Code.
Scenario 2:
My TestModel-Object has ProjectDescription Property as string with MaximumLength 80 and MinimumLength of 5.
Enter 5 Characters in the MaskedInput Field, you can not deleting this Characters.
Only overwrite from first Position is allowed.
But... you can deleting the Characters, when the Count of Characters in the Field < Definition of MinimumLength is.
All other Characters at Position > MinimumLength is deletable.
MainWindow.xaml
MainWindow.cs
TestModel.cs
i have any Problems with the MaskedInput Control.
Scenario 1:
Validation Error Messages not showed by Application Start.
My Custom ControlTemplate for Validation.ErrorTemplate is showed,
but the ErrorMessage is Empty. This is a little bit funny.
You can see the Validation Methods in my TestModel Code.
Scenario 2:
My TestModel-Object has ProjectDescription Property as string with MaximumLength 80 and MinimumLength of 5.
Enter 5 Characters in the MaskedInput Field, you can not deleting this Characters.
Only overwrite from first Position is allowed.
But... you can deleting the Characters, when the Count of Characters in the Field < Definition of MinimumLength is.
All other Characters at Position > MinimumLength is deletable.
MainWindow.xaml
<
Window
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
x:Class
=
"Telerik_Forum.MainWindow"
xmlns:numericinput
=
"clr-namespace:Telerik.Windows.Controls.MaskedInput;assembly=Telerik.Windows.Controls.Input"
Title
=
"MainWindow"
Height
=
"150"
Width
=
"525"
>
<
Window.Resources
>
<
ControlTemplate
x:Key
=
"CustomErrorTemplate"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
Border
Margin
=
"-1"
VerticalAlignment
=
"Center"
>
<
AdornedElementPlaceholder
x:Name
=
"Holder"
/>
</
Border
>
<
Border
Margin
=
"3 1 0 1"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Center"
>
<
StackPanel
>
<
TextBlock
Text
=
"!!!"
ToolTip
=
"{Binding ElementName=Holder, Path=AdornedElement.DisplayErrorMessage}"
/>
</
StackPanel
>
</
Border
>
</
StackPanel
>
</
ControlTemplate
>
</
Window.Resources
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"30"
/>
<
RowDefinition
Height
=
"30"
/>
<
RowDefinition
Height
=
"30"
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"Auto"
/>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<
TextBlock
Grid.Column
=
"0"
Grid.Row
=
"0"
Text
=
"Project Number:"
/>
<
telerik:RadMaskedNumericInput
Grid.Column
=
"1"
Grid.Row
=
"0"
Width
=
"100"
Validation.ErrorTemplate
=
"{StaticResource CustomErrorTemplate}"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Value
=
"{Binding ProjectNumber, ValidatesOnDataErrors=True, ValidatesOnNotifyDataErrors=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsClearButtonVisible
=
"False"
Mask
=
"#4"
AutoFillNumberGroupSeparators
=
"False"
Placeholder
=
" "
/>
<
TextBlock
Grid.Column
=
"0"
Grid.Row
=
"1"
Text
=
"Cost Summary:"
/>
<
telerik:RadMaskedNumericInput
Grid.Column
=
"1"
Grid.Row
=
"1"
Width
=
"100"
Validation.ErrorTemplate
=
"{StaticResource CustomErrorTemplate}"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Value
=
"{Binding CostSummary, ValidatesOnDataErrors=True, ValidatesOnNotifyDataErrors=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsClearButtonVisible
=
"False"
Mask
=
"#9.2"
AutoFillNumberGroupSeparators
=
"False"
Placeholder
=
" "
/>
<
TextBlock
Grid.Column
=
"0"
Grid.Row
=
"2"
Text
=
"Project Description:"
/>
<
telerik:RadMaskedTextInput
Grid.Column
=
"1"
Grid.Row
=
"2"
Width
=
"300"
AllowInvalidValues
=
"True"
UpdateValueEvent
=
"PropertyChanged"
Validation.ErrorTemplate
=
"{StaticResource CustomErrorTemplate}"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Value
=
"{Binding ProjectDescription, ValidatesOnDataErrors=True, ValidatesOnNotifyDataErrors=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Mask
=
""
IsClearButtonVisible
=
"False"
numericinput:MaskedInputExtensions.MinTextLength
=
"5"
numericinput:MaskedInputExtensions.MaxTextLength
=
"80"
Placeholder
=
" "
/>
</
Grid
>
</
Window
>
MainWindow.cs
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
InitializeComponent();
TestModel m_Model =
new
TestModel(0, 0,
"Test"
);
this
.DataContext = m_Model;
}
}
TestModel.cs
public
class
TestModel : IDataErrorInfo
{
public
TestModel()
{ }
public
TestModel(
int
project_number,
double
cost_summary,
string
project_description)
{
this
.ProjectNumber = project_number;
this
.CostSummary = cost_summary;
this
.ProjectDescription = project_description;
}
public
int
ProjectNumber {
get
;
set
; }
public
double
CostSummary {
get
;
set
; }
[StringLength(10, MinimumLength = 5)]
public
string
ProjectDescription {
get
;
set
; }
public
string
Error
{
get
{
return
this
[
string
.Empty]; }
}
public
string
this
[
string
propertyName]
{
get
{
string
validationResult =
null
;
switch
(propertyName)
{
case
"ProjectNumber"
:
validationResult = Validate_ProjectNumber();
break
;
case
"CostSummary"
:
validationResult = Validate_CostSummary();
break
;
case
"ProjectDescription"
:
validationResult = Validate_ProjectDescription();
break
;
default
:
throw
new
ApplicationException(
"Unknown Property being validated on Product."
);
}
return
validationResult;
}
}
private
string
Validate_ProjectNumber()
{
string
Result =
""
;
if
(ProjectNumber == 0)
{
Result =
"Please Enter a Project Number."
;
}
if
(ProjectNumber < 1 || ProjectNumber > 9999)
{
Result =
"Only ProjectNumber Between 1 and 9999"
;
}
return
Result;
}
private
string
Validate_CostSummary()
{
string
Result =
""
;
if
(CostSummary == 0)
{
Result =
"Please Enter Cost Summary Value."
;
}
else
if
(CostSummary < 0.0)
{
Result =
"Cost Summary allows only positive Values."
;
}
return
Result;
}
private
string
Validate_ProjectDescription()
{
string
Result =
""
;
if
(ProjectDescription.Length == 0)
{
Result =
"Please Enter a Project Description"
;
}
else
if
(ProjectDescription.Length < 5)
{
Result =
"You must enter a Project Description with 5 Characters."
;
}
return
Result;
}
}