Skip to content

Instantly share code, notes, and snippets.

@ytabuchi
Created September 3, 2015 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytabuchi/26f382375b3b90d4a1be to your computer and use it in GitHub Desktop.
Save ytabuchi/26f382375b3b90d4a1be to your computer and use it in GitHub Desktop.
ListViewの要素を動的に増したい場合はどうする?
var listItems = new ObservableCollection<CellItems>();
foreach (var i in Enumerable.Range(0, 10))
{
listItems.Add(new CellItems { StringItem = "StringItem-" + i });
}
var list = new ListView
{
HasUnevenRows = true,
ItemsSource = listItems,
ItemTemplate = new DataTemplate(typeof(FlexibleCell)),
};
var button = new Button { Text = "Change List" };
button.Clicked += (sender, e) =>
{
listItems.Add(new CellItems { StringItem = "NewStringItem", AdditionlItem = "AdditionalItem" });
};
~~~~~~~~~~~~~~~~~~~~
public FlexibleCell() {
var stringItem = new Label();
stringItem.SetBinding(Label.TextProperty, "StringItem");
var additionalItem = new Label();
additionalItem.SetBinding(Label.TextProperty, "AdditionalItem");
View = new StackLayout
{
Orientation = StackOrientation.Horizontal,
Children =
{
stringItem,
additionalItem,
},
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment