JamesBondCaesar
JamesBondCaesar

Reputation: 273

How to create a table like ListView in AvaloniaUi?

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.

Upvotes: 0

Views: 8796

Answers (3)

timkicker
timkicker

Reputation: 37

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.

Upvotes: 0

Konstantin S.
Konstantin S.

Reputation: 1505

I think ListBox would be a more suitable alternative than ItemsRepeater

Upvotes: 4

frankenapps
frankenapps

Reputation: 8281

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.

Upvotes: 3

Related Questions