Comments (7)
Hello Hot-Gun, thank you for your interest in Windows Community Toolkit!
I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible.. Other community members may also answer the question and provide feedback 🙌
from dotnet.
@Hot-Gun Thanks for highlighting the issue but it does seem like that the only letters that are triggered to be added at end of the list (not in alphabetical) are not part of the existing Items list. I am not certain if it's intended by design. I will tag this and see if community members can provide further insight.
Attached is the video of the sample
V4cURZqsne_Trim.mp4
from dotnet.
FYI @vgromfeld @Sergio0694 who have knowledge in this space.
But Add
will always add to the end of a collection, there should be an InsertItem
method you can call as well.
You'd have to figure out where you need to insert the item into your collection I believe, otherwise the sorting part should be handled by the CollectionViewSource
?
from dotnet.
So, @Sergio0694 didn't help me. But I found a solution. Maybe someone will show a more elegant option, but here's what I replaced, based on an example from the WindowsCommunityToolkit:
I will do tests in the future to make sure that this is not causing the problem.
Original from example:
var groupName = GetGroupName(newContact);
var targetGroup = _contactsSource.FirstOrDefault(group => group.Key == groupName);
if (targetGroup is null)
{
_contactsSource.Add(new ObservableGroup<string, Person>(groupName, new[] { newContact }));
}
else
{
targetGroup.Add(newContact);
}
My code:
var groupName = GetGroupName(newContact);
var targetGroup = _contactsSource.FirstOrDefault(group => group.Key == groupName);
if (targetGroup is null)
{
List<string> tempList = _contactsSource.ToDictionary(x => x.Key).Keys.ToList();
tempList.Add(groupName);
tempList.Sort();
_contactsSource.Insert(tempList.IndexOf(groupName), new ObservableGroup<string, Person>(groupName, new[] { newContact }));
}
else
{
List<Person> tempList = targetGroup.ToList();
tempList.Add(newContact);
var query = tempList.OrderBy(x => x.Name);
tempList = query.ToList();
targetGroup.Insert(tempList.IndexOf(newContact), newContact);
}
from dotnet.
@Hot-Gun, the sample page is very basic. It only uses Add()
because it was simpler to showcase the behavior of the ObservableGroupedCollection<TKey, TValue>
.
Since it mostly just wraps an ObservableCollection<T>
, it is up to you to insert the data where you want using InsertItem
as @michael-hawker said.
You can simplify your code by doing a binary search in the groups list or the existing group content to find the insertion index.
Sadly, ObservableCollection<T>
does not have it implemented but you can easily add your own.
This will improve the performances.
from dotnet.
@Hot-Gun this should ideally be supported by the CollectionViewSource
helpers, we have some in the Toolkit, but not one that supports sorting and grouping. I've opened this WinUI issue on the topic please up-vote that one.
Though there is certainly room to improve our sample here as well.
from dotnet.
Closing this, as #168 did add new APIs to insert items in the right (sorted) position 🙂
from dotnet.
Related Issues (20)
- Can't get FlowExceptionsToTaskScheduler to work for error handling (with TaskScheduler.UnobservedTaskException) HOT 2
- Add an option to [ObservableProperty] - generate a private setter HOT 2
- IconTintColorBehavior throws exception when navigation happens via Shell Tab and app/system theme is changed HOT 1
- Guard.IsNotNull doesn't prevent warning CA1062 on .NET Standard 2.0
- SpeechToText.ListenAsync reports twice HOT 1
- CommandParameters other than Strings are not acceptable for RelayCommands?
- ObserveableProperty and Nullable Can Generate Warnings
- RelayCommand attribute only works in .Net 6 and above?
- Generated code tries to assign to a read only `ObservableCollection` HOT 1
- Factor ObservableObject into separate assembly HOT 4
- Automatically determine dependent properties with [ObservableProperty] HOT 1
- Better support for notifying cascading calculated properties HOT 1
- ObservableProperty with NotifyCanExecuteChangedFor exception occurs
- Adding property using [ObservableProperty] breaks hot reload HOT 5
- ObservableProperty attribute with specific accessor HOT 1
- Typo in Guard.ThrowHelper.ThrowArgumentNullExceptionForIsNotNull
- Crash when command parameter is MS.Internal.NamedObject "DisconnectedItem"
- `PropertyChanged` triggered on empty string HOT 3
- Setting 'CanExecute' doesn't change the status of Button controls when they are bound to RelayCommand HOT 2
- Adding version 8.2.2 to existing Maui project breaks xaml file(s) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotnet.