次の方法で共有


BindableLayout 拡張機能

BindableLayout 拡張機能は、その EmptyViewItemSourceItemTemplate の構成をサポートする一連の拡張メソッドを提供します。

EmptyView

EmptyView メソッドでは、ILayoutEmptyView プロパティを設定します。

次の例では、EmptyViewnew Label().Text("No Items Found") に設定します。

new VerticalStackLayout().EmptyView(new Label().Text("No Items Found"));

EmptyViewTemplate

EmptyViewTemplate メソッドでは、ILayoutEmptyViewTemplate プロパティを設定します。

次の例では、EmptyViewTemplatenew DataTemplate(() => new Label().Text("No Items Found")) に設定します。

new VerticalStackLayout().EmptyViewTemplate(new DataTemplate(() => new Label().Text("No Items Found")));

EmptyViewTemplate にはオーバーロード メソッドがあり、DataTemplate の初期化に使われる Func<object> を受け入れます。

new VerticalStackLayout().EmptyViewTemplate(() => new Label().Text("No Items Found"));

ItemsSource

ItemsSource メソッドでは、ILayoutItemsSource プロパティを設定します。

次の例では、ItemsSourcenew List<string> { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" } に設定します。

new VerticalStackLayout().ItemsSource(new List<string> { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" });

ItemTemplate

ItemTemplate メソッドでは、ILayoutItemTemplate プロパティを設定します。

次の例では、ItemTemplatenew DataTemplate(() => new Label().Bind(Label.TextProperty, ".") に設定します。

new VerticalStackLayout().ItemTemplate(new DataTemplate(() => new Label().Bind(Label.TextProperty, Binding.SelfPath)));

ItemTemplate にはオーバーロード メソッドがあり、DataTemplate の初期化に使われる Func<object> を受け入れます。

new VerticalStackLayout().ItemTemplate(() => new Label().Bind(Label.TextProperty, Binding.SelfPath));

ItemTemplateSelector

ItemTemplateSelector メソッドでは、ILayoutItemTemplateSelector プロパティを設定します。

次の例では、ItemTemplateSelectornew CustomDataTemplateSelector() に設定します。

new VerticalStackLayout().ItemTemplateSelector(new CustomDataTemplateSelector())

class CustomDataTemplateSelector : DataTemplateSelector
{
  // ...
}