microsoft / microsoft/microsoft-ui-xaml

ListView of NumberBox with Minimum constraint corrupts value when ordered

Open
#10,182 3 comments 0 reactions 0 assignees View on GitHub
area-NumberBox bug team-Controls
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

ListView can change values of underlying data if it contains NumberBox with Minimum constraint. It is possible to assume this extends to other inputs with contraints as well.

### Steps to reproduce the bug

MainWindow.xaml:
```


Sort







```
MainWindow.xaml.cs:
```
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Media.Capture.Frames;

namespace NumberboxText;

public class TestItem : INotifyPropertyChanged
{
private int _order;
private int _min;
private int _current;

public event PropertyChangedEventHandler? PropertyChanged;

public int Order
{
get => _order;
set => SetProperty(ref _order, value);
}

public int Min
{
get => _min;
set => SetProperty(ref _min, value);
}

public int Current
{
get => _current;
set => SetProperty(ref _current, value);
}

protected void SetProperty(ref T field, T value, [CallerMemberName] string propertyName = null)
{
field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

}
public sealed partial class MainWindow : Window
{
public readonly ObservableCollection Items = [];
public MainWindow()
{
this.InitializeComponent();
Items.Add(new TestItem { Order = 3, Min = 3, Current = 3 });
Items.Add(new TestItem { Order = 1, Min = 1, Current = 1 });
Items.Add(new TestItem { Order = 4, Min = 4, Current = 4 });
Items.Add(new TestItem { Order = 2, Min = 2, Current = 2 });

}

private void Button_Click(object sender, RoutedEventArgs e)
{
for (var i = Items.Count - 1; i >= 0; i--)
{
for (var j = 1; j <= i; j++)
{
if (Items[j - 1].Order > Items[j].Order)
{
Items.Move(j - 1, j);
}
}
}
}
}

```

### Expected behavior

Ordering items inside ListView should not cause values to change.

### Screenshots

![Image](https://github.com/user-attachments/assets/fb991cc2-105a-465b-94d0-cdd046c55e92)

### NuGet package version

None

### Windows version

_No response_

### Additional context

Cross-Post from: https://stackoverflow.com/questions/79203554/listview-of-numberbox-with-minimum-constraint-corrupts-value-when-ordered

Replacing whole collection with new, sorted list also causes this behaviour to happen.

Contributor guide

Open the contributing guide

Research direction

Start with the MainWindow.xaml and MainWindow.xaml.cs reproduction using ListView, NumberBox, Minimum, and two-way binding. Run the sorting and collection-replacement scenarios described in the issue, then trace which binding or control update changes the underlying Current values. Done means reordering items no longer changes their bound values, including when a Minimum constraint is present.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.