Skip to content

ListViewProperty

ListView のバインディングを宣言するときに利用するBindablePropertyです。

宣言の方法

BindablePropertyと同様に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()は次のパラメータを指定することができます。

パラメータ必須初期値
itemViewIdstringyes-
makeItemSourceMakeItemSourceDelegateyes-
itemsSourcePathPropertyPathyes-
elementNameInfoElementNameInfoyes-
bindingModeBindingModenoBindingMode.ToTarget
updateTriggerBindingUpdateTriggernoBindingUpdateTrigger.OnSourceChanged
  • itemViewId
    ViewクラスのGuidを指定します。指定するGuidのViewクラスを含むアセンブリについて、事前に ViewInstaller.Install() をしておく必要があります。 ListView.makeItemでこのGuidを元にVisualTreeAssetを取得、インスタンス化し、Viewクラスによってデータバインディングが実行されます。

  • makeItemSourceListView.bindItem が発火する際に、どのように itemsSource の中身を作成するかを定義することができます。
    makeItemSourceで指定した処理の結果がListView内の要素1つ当たりのデータソースとなります。

  • elementNameInfo どのListViewに対してバインディングを構築するかを指定します。

  • bindingMode
    BindingMode を指定します。

  • updateTrigger
    BindingUpdateTrigger を指定します。