Skip to content

fix(number-box) #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(numberbox): fix compile errors and warnings
  • Loading branch information
c0nstexpr committed Mar 29, 2024
commit 919c6f81e36bf882c88680c21b96e59c6aee82f1
6 changes: 0 additions & 6 deletions src/Wpf.Ui.Demo.Simple/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>

<ui:NavigationView x:Name="RootNavigation" Grid.Row="1">
Expand Down Expand Up @@ -94,10 +93,5 @@
<ContextMenu ItemsSource="{Binding ViewModel.TrayMenuItems, Mode=OneWay}" />
</tray:NotifyIcon.Menu>
</tray:NotifyIcon>

<StackPanel Grid.Row="2">
<ui:NumberBox Value="{Binding Value}"/>
<ui:TextBlock Text="{Binding Value}" />
</StackPanel>
</Grid>
</ui:FluentWindow>
13 changes: 0 additions & 13 deletions src/Wpf.Ui.Demo.Simple/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ namespace Wpf.Ui.Demo.Simple;
/// </summary>
public partial class MainWindow : INotifyPropertyChanged
{
private double _value;

public double Value
{
get => _value;

set
{
_value = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value)));
}
}

public MainWindow()
{
DataContext = this;
Expand Down
20 changes: 9 additions & 11 deletions src/Wpf.Ui/Controls/NumberBox/NumberBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

// This Source Code is partially based on the source code provided by the .NET Foundation.

using System.Windows.Controls;
Expand All @@ -20,8 +19,8 @@ namespace Wpf.Ui.Controls;
/// <summary>
/// Represents a control that can be used to display and edit numbers.
/// </summary>
//[ToolboxItem(true)]
//[ToolboxBitmap(typeof(NumberBox), "NumberBox.bmp")]
// [ToolboxItem(true)]
// [ToolboxBitmap(typeof(NumberBox), "NumberBox.bmp")]
public class NumberBox : TextBox
{
private bool _valueUpdating;
Expand Down Expand Up @@ -80,7 +79,7 @@ public class NumberBox : TextBox
nameof(Maximum),
typeof(double),
typeof(NumberBox),
new PropertyMetadata(Double.MaxValue)
new PropertyMetadata(double.MaxValue)
);

/// <summary>
Expand All @@ -90,7 +89,7 @@ public class NumberBox : TextBox
nameof(Minimum),
typeof(double),
typeof(NumberBox),
new PropertyMetadata(Double.MinValue)
new PropertyMetadata(double.MinValue)
);

/// <summary>
Expand Down Expand Up @@ -231,7 +230,7 @@ public double Minimum
}

/// <summary>
/// Gets or sets whether the control will accept and evaluate a basic formulaic expression entered as input.
/// Gets or sets a value indicating whether the control will accept and evaluate a basic formulaic expression entered as input.
/// </summary>
public bool AcceptsExpression
{
Expand Down Expand Up @@ -312,7 +311,6 @@ protected override void OnKeyUp(KeyEventArgs e)
UpdateValueFromText();
ValidateValue(Value);
MoveCaretToTextEnd();
TriggerValueUpdate();
}

break;
Expand Down Expand Up @@ -368,7 +366,7 @@ ControlTemplate newTemplate
base.OnTemplateChanged(oldTemplate, newTemplate);

// If Text has been set, but Value hasn't, update Value based on Text.
if (String.IsNullOrEmpty(Text) && Value != null)
if (string.IsNullOrEmpty(Text) && Value != null)
{
SetCurrentValue(ValueProperty, null);
}
Expand All @@ -391,7 +389,7 @@ protected override void OnLostFocus(RoutedEventArgs e)
/// </summary>
protected virtual void OnValueChanged(DependencyObject d, double? oldValue)
{
var newValue = Value;
double? newValue = Value;

if (Equals(newValue, oldValue))
{
Expand Down Expand Up @@ -425,7 +423,7 @@ private void ValidateValue(double? newValue)
// Correct the text from value
if (Value is null && Text.Length > 0)
{
SetCurrentValue(TextProperty, String.Empty);
SetCurrentValue(TextProperty, string.Empty);
}
else if (GetParser().ParseDouble(Text.Trim()) != Value)
{
Expand All @@ -444,7 +442,7 @@ private void StepValue(double? change)
);
#endif

var newValue = Value ?? 0;
double newValue = Value ?? 0;

if (change is not null)
{
Expand Down