Wpf listview freeze item by index on top năm 2024

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confindential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

" specified. Upon page scroll, user want to have headers freeze. When scrolling through first grid, the headers should freeze. When scrolling through second grid, the headers of Grid

1 should unfreeze and, freeze headers of Grid

2.

In our non-blazor app, we are currently using DataTables solution. As we are rewriting our app by using Blazor, we want to accomplish the same using Syncfusion Blazor Components.

I've got a ListView that I want to sort. I want to keep the selecteditem selected after the sorting operation. The problem I have is that the selecteditem is reset for a very small time to null, that I want to avoid, because other bindings rely on this property. This issue is described in the last part of the post, but not solved.

I tried to add an additional _isSorting boolean, without luck: private void SortConversations() { _isSorting = true; _conversations.Sort(model => model.LastMessageTimeStamp, descending: true); _isSorting = false; } public ConversationViewModel SelectedConversation { get => _selectedConversation; set { if (!_isSorting) { Set(ref _selectedConversation, value); } } }

The problem is, that the Item does not appear as selected in the UI. Even if I try to manually set it again, it requires some additional Task.Delay() between the sort and the (re)selection. That is no proper solution, especially if the pc running the app is slower or faster.

---

I've already tried all the solutions you described. I am using an observable collection and Move() the items. I've also tried to backup the SelectedItem, but as I said it is null for a small time amount. And If I reselect the item, I need to add a delay between the Sorting and the reselection. And that is exactly the problem I am facing. How can I solve this?

I've prepared a minimal example, so you can test the problem real quick:

//github.com/AtosNicoS/ListViewSortIssue

To reproduce the issue:

  1. Click "Reset" Button
  2. Select any item
  3. Click "Sort" Button
  4. Watch and Repeat

What you will see is, that sometimes (50% of the time) after the sorting a wrong(!!) item gets selected. With the additional delay, the correct item will be selected after one second. That is one issue I am focussing.

The other issue is, that SelectedItem is reset to null while sorting the list. I've added code to work around this issue with the _isSorting boolean. It is currently not activated, but should work commented out. You said, observable collections should work better here - they do not. The value is still null. And the issue even becomes more complicated, combined with the delay issue described above.

In my real application (with more data and larger datatemplates) this issue becomes even more complicated. If the selected item is at the top of the list, the sorting+selection works without delay, if it is in the bottom of the list, the item is not selected after sorting anymore.

Adding a delay does not sound like the right solution. I somehow need to wait until the ListView refreshed its items.

Using MVVM, you should bind the IsHitTestVisible property of the ListViewItem to a property of your business object.

An example: We have a list of clsMyClass object, used as ItemsSource for our list. The class clsMyClass has a boolean property IsSelectable Our XAML shoul be like this:

<listview itemssource="{Binding MyList}" selectionmode="Single"> <listview.itemcontainerstyle> <Setter Property="IsHitTestVisible" Value="{Binding IsSelectable}"></setter>

In this way the items with IsSelectable=False will be not visible to the hit test, which means that the ListView will not intercept the mouse events and will not select it once clicked.

Note: this solution is not perfect in a multi-selection environment, because all items can be selected anyway using keybord shortcuts like Ctrl+A or Shift during selection.

Which control is used to display a list of items in a WPF application?

The ListView control provides the infrastructure to display a set of data items in using a different layout or view. For example, a user may want to display data items in a table and also to sort its columns.

What is ListView control?

A list-view control is a window that displays a collection of items. List-view controls provide several ways to arrange and display items and are much more flexible than simple List Boxes. For example, additional information about each item can be displayed in columns to the right of the icon and label.

Chủ đề