0
我有一個listView和item selected event.Here我想讓我的第一個項目在默認情況下出現在視圖上的列表。選擇其他項目應該正常工作。列表視圖中第一項的默認選擇
ListView listView = new ListView
{
ItemsSource = staticSpListDetailses,
ItemTemplate = new DataTemplate(() =>
{
var nameLabel = new Label();
nameLabel.FontSize = 18;
nameLabel.WidthRequest = 180;
nameLabel.HorizontalTextAlignment = TextAlignment.Start;
nameLabel.FontAttributes = FontAttributes.Bold;
nameLabel.SetBinding(Label.TextProperty, "Name");
var subtitlelabel = new Label();
subtitlelabel.FontSize = 16;
subtitlelabel.HorizontalTextAlignment = TextAlignment.Start;
subtitlelabel.TextColor = Color.Silver;
subtitlelabel.SetBinding(Label.TextProperty, "SubTitle");
var arrowmarklabel = new Label();
arrowmarklabel.FontSize = 20;
arrowmarklabel.HorizontalOptions = LayoutOptions.EndAndExpand;
arrowmarklabel.VerticalOptions = LayoutOptions.Center;
arrowmarklabel.TextColor = Color.Black;
arrowmarklabel.Text = ">";
arrowmarklabel.FontAttributes = FontAttributes.Bold;
var arrowmarklabel1 = new Label();
arrowmarklabel1.WidthRequest = 90;
var insideStackLayout = new StackLayout
{
Orientation = StackOrientation.Vertical,
VerticalOptions = LayoutOptions.Center,
Spacing = 5,
Children =
{
nameLabel,subtitlelabel
}
};
var image = new Image();
image.Scale = 0.8;
image.SetBinding(Image.SourceProperty, "ImageSourceUrl");
return new ViewCell
{
View = new StackLayout
{
Padding = new Thickness(10,0, 5, 0),
Orientation = StackOrientation.Horizontal,
Children = {
new StackLayout {
VerticalOptions = LayoutOptions.Center,
Orientation=StackOrientation.Horizontal,
Children = {
image,insideStackLayout,arrowmarklabel
}
}
}
}
};
})
};
這裏是我的Itemselected事件:
listView.ItemSelected += (sender, e) =>
{
var data = ((ListView)sender).SelectedItem as StaticListDetails;
Detail = data.page;
};
什麼是做第一個項目需要我的代碼的變化來選擇在列表視圖中的默認。