This is a migrated thread and some comments may be shown as answers.

RadMaskedNumericInput Text Foreground colour convertor getting randomly fired

3 Answers 100 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Sandeep
Top achievements
Rank 1
Sandeep asked on 22 May 2013, 04:29 PM
Hi,

Overview:-
We are using RadMaskedNumericInput control embedded in a RadGridView Cell for allowing user to edit the existing decimal values. Also, the Foreground property of the RadMaskedNumericInput control is bound to a decimal value and a converter (named ValueToColorConvertor) is applied which turns the foreground red for negative numbers and keep it black for non-negative number.
Problem:-
Now the problem that on refreshing the data source of the GridView (in whoes cell RadMaskedNumericInput control is embedded) RadMask control's foreground behave's awkwardly and for few of the cells sometime a positive number is shown red and sometimes a negative number is shown black (see the attached snapshot)

Analysis:-
I have verified that when data is refreshed for parent RadGridView then ValueToColor foreground converter is not invoked for all the radmaskednumericInput control instances. this converter is invoked randomly for 7-8 instances out of 13 instances shown in the controls attached snapshot.

Converter and Behavior applie are :-
1) ValueToColorConverter:- converts decimal value to Red/Black colour brush during  first time load/refresh of the data.
2) TargetExposureConverter:- which is a multivalue converter to attach parameters to the RadMaskedNumericInput valuechanging command
3) RadMaskedInputValueChangingBehavior:- This behaviour changes the foreground of the RadMaskedNumericInput control's text on value changed.

 

public class ValueToColorConverter : IValueConverter

{

 

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

{

 

var brush = new SolidColorBrush(Colors.Black);

 

Double doubleValue = 0.0;

 

Double.TryParse(value.ToString(), out doubleValue);

 

if (doubleValue < 0)

brush =

 

new SolidColorBrush(Colors.Red);

 

return brush;

}

 

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

{

 

throw new NotImplementedException();

}

}


-----------------------------------------------

 

public class TargetExposureConverter : IMultiValueConverter

{

 

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)

{

 

if (values == null)

 

return null;

 

if (values.Length != 2)

 

throw new ApplicationException("Expecting 2 parameters in TargetExposureConverter");

 

var targetExposureCmdParameter = new TargetExposureEditedCmdParam();

 

decimal value;

 

decimal.TryParse(System.Convert.ToString(values[0]), out value);

targetExposureCmdParameter.TargetExposure = value;

 

var targetExposureCell = values[1] as GridViewCell;

 

if (targetExposureCell != null && targetExposureCell.ParentRow != null)

{

targetExposureCmdParameter.CurrentRow = targetExposureCell.ParentRow.Item

 

as CcyExposureCurrencySummary;

}

 

return targetExposureCmdParameter;

}

 

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

{

 

throw new NotImplementedException();

}

}


-----------------------------------

 

public class RadMaskedInputValueChangingBehavior : Behavior<RadMaskedInputBase>

{

 

protected override void OnAttached()

{

 

base.OnAttached();

AssociatedObject.ValueChanging += OnValueChanging;

}

 

protected override void OnDetaching()

{

 

base.OnDetaching();

AssociatedObject.ValueChanging -= OnValueChanging;

}

 

void OnValueChanging(object sender, RadMaskedInputValueChangingEventArgs e)

{

 

var maskedInputControl = sender as RadMaskedNumericInput;

 

if (maskedInputControl == null)

 

return;

 

if (e.NewValue == null)

 

return;

 

double newVal;

 

if (!double.TryParse(Convert.ToString(e.NewValue), out newVal))

 

return;

maskedInputControl.Foreground = newVal < 0

?

 

Brushes.Red

:

 

Brushes.Black;

}

}

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 27 May 2013, 07:55 AM
Hi Sandeep,

This seems to be very strange issue that we are unable to reproduce in our test project. Could you please check it out in the attachment and let us know if we are missing something? You can modify it and send it back to us in a support ticket where your 24-hours response time is guaranteed. On the other hand, we would highly appreciate if you can send us your isolated scenario, this way we would be better able to investigate it and provide a possible solution/workaround. Thank you in advance for your cooperation.

Regards,
Petar Mladenov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sandeep
Top achievements
Rank 1
answered on 28 May 2013, 09:48 AM
Thanks for your response Petar.

I will try to reproduce the random behaviour by modifying the project provided by you.


Thanks,
Sandeep
0
Petar Mladenov
Telerik team
answered on 28 May 2013, 12:58 PM
Hello Sandeep,

 We are looking forward to your reply.

Regards,
Petar Mladenov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Sandeep
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Sandeep
Top achievements
Rank 1
Share this question
or