Created
September 3, 2015 06:04
-
-
Save ytabuchi/26f382375b3b90d4a1be to your computer and use it in GitHub Desktop.
ListViewの要素を動的に増したい場合はどうする?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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