0
私は自分のxamarin形式でリストビューを持っています。私のprivate voidで後で使用できるItemSelectedとItemTappedがあります。私はどのようにItemSelectedとItemTappedをコードで宣言するのだろうか。listviewのItemSelectedをコードで宣言するには? c#
<ListView ItemsSource="{x:Static local:interactiveListViewXaml.items}" ItemSelected="OnSelection" ItemTapped="OnTap" IsPullToRefreshEnabled="true" Refreshing="OnRefresh">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
</ViewCell.ContextActions>
<StackLayout Padding="15,0">
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
リストビューを作成し、コードでItemSelectedを宣言したいとします。 ItemSelectedとItemTappedで以下のようなものがあります。
ListView mylist = new ListView
{
ItemsSource = test,
ItemTemplate = new DataTemplate(() =>
{
Label nameLabel = new Label();
nameLabel.SetBinding(Label.TextProperty, "Name");
Label nameLabel2 = new Label();
nameLabel2.SetBinding(Label.TextProperty, "reading");
// Return an assembled ViewCell.
return new ViewCell
{
View = new StackLayout
{
Padding = new Thickness(0, 5),
Orientation = StackOrientation.Horizontal,
Children =
{
new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Spacing = 0,
Children =
{
nameLabel,
nameLabel2
}
}
}
}
};
})
};
は、なぜあなたは、テンプレートを定義することの背後にあるコードを使用していますか? –