WrapPanel children order - wpf

i use WPF and add WrapPanel children in User Control panel.
like that:
SearchPanel sp = new SearchPanel();
sp.Clock = clock;
sp.Name = item.CustomerTwo;
sp.Color = "Purple";
wPanel.Children.Add(sp);
how i organize this added panels

The simple answer to this question is that they appear in the order that they are added to the Children collection.
If you were adding them explicitly using XAML they would appear in the same order that they appear in the XAML.
If you were adding them by binding the ItemsSource of the WrapPanel then they would appear in the order that the bound collection presents them.
As for your specific example...
In your linked code, the colour is based on a date indirectly obtained from each "customer" item. To order the WrapPanel based on this, you will need to sort your customer items by that same criteria first.
Unfortunately, the date logic is convoluted (using a DB relation to a Days table and then some awkward date manipulation code). You could use that convoluted date logic in a Comparison function to sort the customer items first. Or you could add a property to the "newSearchPanel" class which you calculate while constructing them and add them to a temp list, which you sort before finally pushing them into the WrapPanel.

Related

Order elements in view or in view model?

I am using the MVVM pattern and I would like to sort the elements on a datagrid. In my view model I have an ObservableCollection with the element for the datagrid.
In the datagrid I can sort element cliking in the column name, so that is nice, and for multiple columns. I like this feature.
However, I would like to do some more specific ordering, for example show first the element which the ColumnB has "valueC" and later the rest of the elements, and when I sort for a column name, order for that column but show first the elements with "valueC" and later the rest of the elements sorted by the column that I clicked.
To do that, I can sort the elements in the ObservableCollection of the view model, but I think that this functionality is more something that it would be done in view, plus because I would like to sort by columns, so I would have to say to the view the column that is clicked.
However, I don't know if it is posible to do this kind of complex sorts in the view, perhaps with some converter or with any way.
Thank so much.
Every logic has to be done in the ViewModel. View must not know anything about the logic behind displayed datas.
In a simple case you could order your items in a view but in a realistic case, ordering will not affect only visible items but it affects also items not shown because of the paging.

XamDataGrid sort in Reverse Order

I have xamdatagrid in which I Add Item, every time new item added it goes to the bottom. I want every time I add item it should be on the top row "like reverse sort"
also in field layout setting I am adding new record on top.
note: I removed sort option from field
Note: I dont want to sort by any field except by row insertion order if its in xamdatagrid.
or sort of list like list.reverse possibility in xamdatagrid.
Assuming you're binding your grid to an ObservableCollection, use the Insert(0, item) method.
You can also use a CollectionViewSource for your grid's data source and set the sort there, while calling Add(item) on your source collection normally.

Can WPF CollectionViews be created to bring together multiple columns of data

I have about a dozen ObservableCollections that hold objects which have dates, singles and integers. All collections are of the same length and have data added and removed at the same time. One of the ObservableCollections is the main one and is needed when referring to the others.
Is there a way to use CollectionViews to bring 2 of these ObservableCollections together in such a way that they look like one ObservableCollection having the total of all of the original columns when data bound to a datagrid and/or chart? If so does anyone have an example?
Everything I have found shows the data from both sources being brought together by adding one on top of the other in what I would call a stack of data .
Thanks
Not pretty but I have a similar application.
Have a class with 5 base properties then a variable number of fields.
The fields I put in a List.
Can bind rows to a collection but not columns.
So I use a ListView Gridview where I build up the columns in code behind.
Bind the columns to Field[0], Field[1], ...
In you case you could have base class Bclass with the base Properties and a Property List
In your List<Fields> you just iterate the properties of the List<ExtensionClass>
Clearly the List<Bclass> needs to all have List<Extension> class with the same length in every item of the binding breaks.

Edit collection in separated ListBoxes

I have source elements like this:
var collection = new ObservableCollection<SourceItems>(source);
source implements INotifyPropertyChanged
I need to edit and view this collection in CheckListBoxes (listBox with checkBoxes from WPFToolKit)with rules:
every CheckListBoxes must be sort by one of collection's field. Collection has order field for each CheckListBox. For example - ItemOrder.
visible elements in one listBox depend on checked items from other.
Every CheckListBox has itemsSource
checkListBox1.ItemsSource=collection;
So, if i check items in one listBox i must see only checked items in other.
And every listBox must be sorted by one of source's field
listBox1 by field orderItem
listBox2 by field orderVisibleItem and so on.
User can move elements in each listBoxes and it must not affect ordering in other.
I tried create CollectionViewSource for every ListBox. But when I sort one, it sort each other.
Linq for filtering and sortnig don't work too, because changes not updating dynamicly.
Is there best way to create such functionality?
You should use CollectionViewSource.
I'm guessing that you used CollectionViewSource.GetDefaultView(.. ) ? you should create two NEW views for the collection:
CollectionViewSource cvs = new CollectionViewSource() { Source = TheCollection };

Custom sorting logic for groups using CollectionViewSource

I have a list of "stuff" which needs to be filtered then displayed in a grouped and sorted manner. The data needed to calculate the grouping and sorting order is not available as simple properties - there needs to be some work done in code to calculate the order and groups.
CollectionViewSource lets me define custom filter and sort logic - so far so good. It also lets me bind GroupDescriptions to a value converter so that I can generate the group names.
The last thing I want to do is control the order that the generated groups appear and this is causing me pain!
Everything I see about CollectionViewSource.SortDescriptions says that it will sort groups by a property name, but I don't have a property available to sort by. SortDescriptions can't be bound to a value converter like GroupDescriptions can and I'm out of other ideas.
So - how do you implement custom sorting logic of CollectionViewSource groups?
This post on Bea Stollnitz' blog, and the GitHub repo, demonstrates how you can do that. You will have to sort by the criteria of your grouping first. Even if this is not a concrete property, it should be possible to sort your items using the same logic that you use to group them, isn't it?! Certainly, this is not possible using a SortDescription instance, but you could instead use the ListCollectionView.CustomSort property and specify an appropriate IComparer implementation.

Resources