Skip to content

ListViewProperty

This is a BindableProperty used when declaring bindings for ListView.

How to Declare

As with BindableProperty, you can declare by calling ListViewProperty<T>.Create().

csharp
private static readonly ListViewProperty<AlarmInfoViewModel> ListDataSourceProperty =
    ListViewProperty<AlarmInfoViewModel>.Create(
        itemViewId: AlarmInfoLayout.UxmlGuid,
        makeItemSource: MakeItem,
        itemsSourcePath: PropertyPath.FromName(nameof(AlarmInfoListViewModel.Current)),
        elementNameInfo: ElementNames.AlarmsList
    );

private static AlarmInfoViewModel MakeItem(int index)
{
    var newInfo = new AlarmInfo
    {
        isEnabled = true,
        id = Guid.NewGuid().ToString(),
        info = $"Alarm {index + 1}",
        timeStringIso8601 = DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:sszzz"),
    };
    return new AlarmInfoViewModel(newInfo);
}

Parameters

TabViewProperty<T>.Create() can specify the following parameters:

ParameterTypeRequiredDefault Value
itemViewIdstringyes-
makeItemSourceMakeItemSourceDelegateyes-
itemsSourcePathPropertyPathyes-
elementNameInfoElementNameInfoyes-
bindingModeBindingModenoBindingMode.ToTarget
updateTriggerBindingUpdateTriggernoBindingUpdateTrigger.OnSourceChanged
  • itemViewId
    Specifies the Guid of the View class. For the assembly containing the View class with the specified Guid, you need to call ViewInstaller.Install() in advance. In ListView.makeItem, this Guid is used to obtain and instantiate a VisualTreeAsset, and data binding is executed by the View class.

  • makeItemSource
    Defines how to create the contents of itemsSource when ListView.bindItem is triggered.
    The result of the process specified by makeItemSource becomes the data source for each item in the ListView.

  • elementNameInfo
    Specifies which ListView to construct the binding for.

  • bindingMode
    Specifies BindingMode.

  • updateTrigger
    Specifies BindingUpdateTrigger.