Skip to content

Commit d7da38b

Browse files
committed
possibily fixed 3780, adjusted the demo app to play around and reproduce the bug
1 parent d82fb55 commit d7da38b

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/MainDemo.Wpf/NumericUpDown.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
<smtx:XamlDisplay Margin="10,5"
3636
VerticalAlignment="Top"
3737
UniqueKey="decimalUpDown_default">
38-
<materialDesign:DecimalUpDown ValueStep="0.5" Minimum="-2.5" Maximum="2.5" />
38+
<StackPanel>
39+
<materialDesign:DecimalUpDown Value="{Binding MyDecimal, Mode=TwoWay}" ValueStep="0.5" Minimum="-2.5" Maximum="2.5" />
40+
<TextBlock Text="{Binding MyDecimal, Mode=TwoWay}" />
41+
<Button Content="a button to focus"/>
42+
</StackPanel>
3943
</smtx:XamlDisplay>
4044

4145
<smtx:XamlDisplay Margin="10,5"
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
namespace MaterialDesignDemo;
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
3+
namespace MaterialDesignDemo;
24

35
public partial class NumericUpDown : UserControl
46
{
5-
public NumericUpDown() => InitializeComponent();
7+
public NumericUpDown()
8+
{
9+
InitializeComponent();
10+
this.DataContext = new MyVM();
11+
}
12+
}
613

14+
public partial class MyVM : ObservableObject
15+
{
16+
[ObservableProperty]
17+
private decimal _myDecimal;
718
}

src/MaterialDesignThemes.Wpf/UpDownBase.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,9 @@ private void OnTextBoxFocusLost(object sender, EventArgs e)
213213
{
214214
if (TryParse(textBoxField.Text, CultureInfo.CurrentUICulture, out T? value))
215215
{
216-
SetCurrentValue(ValueProperty, value);
217-
}
218-
else
219-
{
220-
textBoxField.Text = Value?.ToString();
216+
SetCurrentValue(ValueProperty, CoerceNumericValue(this, value));
221217
}
218+
textBoxField.Text = Value?.ToString();
222219
}
223220
}
224221

0 commit comments

Comments
 (0)