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()は次のパラメータを指定することができます。
| パラメータ | 型 | 必須 | 初期値 |
|---|---|---|---|
| itemViewId | string | yes | - |
| makeItemSource | MakeItemSourceDelegate | yes | - |
| itemsSourcePath | PropertyPath | yes | - |
| elementNameInfo | ElementNameInfo | yes | - |
| bindingMode | BindingMode | no | BindingMode.ToTarget |
| updateTrigger | BindingUpdateTrigger | no | BindingUpdateTrigger.OnSourceChanged |
itemViewId
ViewクラスのGuidを指定します。指定するGuidのViewクラスを含むアセンブリについて、事前にViewInstaller.Install()をしておく必要があります。ListView.makeItemでこのGuidを元にVisualTreeAssetを取得、インスタンス化し、Viewクラスによってデータバインディングが実行されます。makeItemSource
ListView.bindItemが発火する際に、どのようにitemsSourceの中身を作成するかを定義することができます。makeItemSourceで指定した処理の結果がListView内の要素1つ当たりのデータソースとなります。elementNameInfo どの
ListViewに対してバインディングを構築するかを指定します。bindingMode
BindingModeを指定します。updateTrigger
BindingUpdateTriggerを指定します。