How to create a table like ListView in AvaloniaUi?

6.6k views Asked by At

How to create a table like ListView in Avalonia ui ? I sow that ListView in only planning, but I am shure that there are same variants of how to do it.

3

There are 3 answers

0
timkicker On

As you already mentioned, there is currently no support for a ListView. Although a ListBox could be an alternative for your use case.

<ListBox Items="{Binding MyItems}"/>

To get headers to work, please take a look at this example.

0
Konstantin S. On

I think ListBox would be a more suitable alternative than ItemsRepeater

0
frankenapps On

You can use the ItemsRepeater. It is a very flexible and easy to use control. You can generate a basic ListView like so:

XAML:

<ItemsRepeater Items="{Binding MyList}"></ItemsRepeater>

ViewModel:

public class MainWindowViewModel : ViewModelBase
{
    private ObservableCollection<String> myList = new ObservableCollection<string>(new string[] {"Row 1", "Row 2", "Row 3"});
    public ObservableCollection<String> MyList
    {
        get => myList;
        set => this.RaiseAndSetIfChanged(ref myList, value);
    }
}

If you want your rows to be selectable / highlight them on hover, you can do all that. Check out the ItemsRepeater page in the AvaloniaUI ControlCatalog for a more sophisticated sample.