A bug in NumericUpDown

Nov 8, 2010 at 12:37 PM

Great job! I encountered what appears to be a bug in NumericUpDown. When initial Value is the same as Maximum, Spinner button still allows an increase by 1. To fix it, I added to OnIncrement() the following test preceding actual increment: if (Value < Maximum).

For completeness, I also added if (Value > Minimum) preceding decrement in OnDecrement().

Regards,

GG

Nov 8, 2010 at 1:22 PM

Good find, I guess I didn't think about that one :0)

Nov 8, 2010 at 1:22 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Nov 8, 2010 at 1:38 PM

I tested out your scenario:

<extToolkit:NumericUpDown Value="10"Maximum

="10" />

But it works as expected.  I can not increment by one.  Could you provide an example to reproduce the bug?

Nov 8, 2010 at 4:08 PM

No problem. In my app, I used binding, which should not make a difference. In any case, I will try to write code to reproduce it.

Thanks for a quick response,

GG

From: brianlagunas [mailto:notifications@codeplex.com]
Sent: Monday, November 08, 2010 9:39 AM
To: genador@gmail.com
Subject: Re: A bug in NumericUpDown [wpftoolkit:233860]

From: brianlagunas

I tested out your scenario:

<extToolkit:NumericUpDown Value="10"Maximum

="10" />

But it works as expected. I can not increment by one. Could you provide an example to reproduce the bug?

Read the full discussion online.

To add a post to this discussion, reply to this email (wpftoolkit@discussions.codeplex.com)

To start a new discussion for this project, email wpftoolkit@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Nov 8, 2010 at 4:45 PM

Hi Brian,

I tried to send an attachment reproducing the bug, but it was rejected. Here is my example:

MainWindow.xaml

Window x:Class="NudBug.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
Title="MainWindow" Height="350" Width="525">
<StackPanel Orientation="Vertical">
<WrapPanel Margin="10" Orientation="Horizontal">
<Label>Works OK:</Label>
<toolkit:NumericUpDown Value="10" Maximum="10" />
</WrapPanel>
<WrapPanel Margin="10" Orientation="Horizontal">
<Label>Has a bug:</Label>
<toolkit:NumericUpDown Name="numPage" Margin="5" Width="45" Height="20" Value="{Binding CurrentPage, Mode=TwoWay}"
Increment="1" Maximum="{Binding TotalPages, Mode=OneWay}" Minimum="1" />
</WrapPanel>
</StackPanel>
</Window>

MainViewMode.cs

public class MainViewModel
{
public int CurrentPage { get; set; }
public int TotalPages { get; set; }

public MainViewModel()
{
CurrentPage = 10;
TotalPages = 10;
}
}

App.xaml

<Application x:Class="NudBug.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="OnStartup">
<Application.Resources>

</Application.Resources>
</Application>

App.xaml.cs

public partial class App : Application
{
private void OnStartup(object sender, StartupEventArgs e)
{
var viewModel = new MainViewModel();
var view = new MainWindow { DataContext = viewModel };
view.Show();
}
}

From: brianlagunas [mailto:notifications@codeplex.com]
Sent: Monday, November 08, 2010 9:39 AM
To: genador@gmail.com
Subject: Re: A bug in NumericUpDown [wpftoolkit:233860]

From: brianlagunas

I tested out your scenario:

<extToolkit:NumericUpDown Value="10"Maximum

="10" />

But it works as expected. I can not increment by one. Could you provide an example to reproduce the bug?

Read the full discussion online.

To add a post to this discussion, reply to this email (wpftoolkit@discussions.codeplex.com)

To start a new discussion for this project, email wpftoolkit@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Nov 9, 2010 at 12:27 AM

I was able to duplicate your issue.  A quick fix would be to define you NUmericUpDown like this:

<extToolkit:NumericUpDown Name="numPage" Margin="5" Width="45" Height="20" Maximum="{Binding TotalPages}" Value="{BindingCurrentPage

}" Increment="1" Minimum="1" />

Notice that the Maximum is declared FIRST.  What is happening is that the Value is set before the Maximum is set, therefore the control thinks that the current Maximum is default(double).  It Maximum won't be re-evaluated untill the Value changes again.  I will put a fix in the source code ASAP.  But once again, your workaround is to define all other properties before the Value property.

Nov 9, 2010 at 12:34 AM

The fix has been checked into source control.