Hello I encountered a bug or odd behaviour in the RadNumericUpDown control. I use caliburn micro as a MVVM framework to bind a simple property to the Value of the control. On KeyDown I check the value and if a condition fails, I reset the value to the last valid state.
The Problem is that the Value is not updated despite the PropertyChanged event firing correctly. The value is updated after the focus is lost.
class
ShellViewModel : Screen
{
/// <summary>
/// Value before change
/// </summary>
protected
double
ValueBeforeChange;
private
double
value;
/// <summary>
/// Gets or sets the value
/// </summary>
public
new
double
Value
{
get
=> value;
set
{
if
(!(Math.Abs(value -
this
.value) >
double
.Epsilon))
{
return
;
}
Console.WriteLine($
"Value changed to {value}"
);
this
.value = value;
NotifyOfPropertyChange(() => Value);
}
}
public
ShellViewModel()
{
Value = 10;
ValueBeforeChange = Value;
}
public
new
void
KeyDown(
object
sender, KeyEventArgs e)
{
if
(e.Key == Key.Return || e.Key == Key.Enter)
{
if
(Value > 20)
{
Value = ValueBeforeChange;
}
else
{
ValueBeforeChange = Value;
}
}
}
}
<
UserControl
x:Class
=
"RadUpDownBug.Views.ShellView"
xmlns:cal
=
"http://www.caliburnproject.org"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"450"
d:DesignWidth
=
"800"
>
<
StackPanel
>
<
telerik:RadNumericUpDown
x:Name
=
"Numeric"
FontSize
=
"24"
ValueFormat
=
"Numeric"
NumberDecimalDigits
=
"2"
Value
=
"{Binding Value, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ShowButtons
=
"False"
UpdateValueEvent
=
"PropertyChanged"
cal:Message.Attach
=
"[Event KeyDown] = [Action KeyDown($this,$eventArgs)];"
Margin
=
"0"
/>
<
TextBox
></
TextBox
>
</
StackPanel
>
</
UserControl
>
So entering a value above 20 and pressing enter should result in the control displaying the last value (10 at the beginning) But it does not. If you click on the TextBox the control is correctly updated.
Why does this happen and how do I fix this?