Dies ist eine Inhaltsdefinition:
Code: Select all
Content = new AbsoluteLayout
{
Children =
{
new ScrollView
{
Content = new Grid
{
Children =
{
collectionView
.Bind(ItemsView.ItemsSourceProperty, nameof(_viewModel.Notifications))
}
}
},
buttonCorner.Text("New")
.LayoutBounds(1, 1, -1, -1).LayoutFlags(AbsoluteLayoutFlags.PositionProportional)
}
}.BackgroundColor(Colors.Snow).Margin(20);
Code: Select all
var collectionView = new CollectionView();
collectionView.ItemTemplate = new DataTemplate(() =>
{
var border = new Border
{
Stroke = Colors.LightGray,
StrokeThickness = 1,
StrokeShape = new RoundRectangle { CornerRadius = 10 },
BackgroundColor = Colors.White//,
//HorizontalOptions = LayoutOptions.FillAndExpand //deprecated, doesn't do anything
};
var grid = new Grid
{
Padding = 10,
RowDefinitions = new RowDefinitionCollection
{
new RowDefinition(GridLength.Auto),
new RowDefinition(GridLength.Auto)
},
ColumnDefinitions = new ColumnDefinitionCollection
{
new ColumnDefinition(GridLength.Auto),
new ColumnDefinition(GridLength.Auto)
}
};
var titleLabel = new Label
{
FontAttributes = FontAttributes.Bold,
FontSize = 18,
TextColor = Colors.Black
};
titleLabel.SetBinding(Label.TextProperty, "Title");
var descriptionLabel = new Label
{
FontSize = 14,
TextColor = Colors.Gray
};
descriptionLabel.SetBinding(Label.TextProperty, "Description");
var buttonDelete = new Button
{
Text = "Delete",
BackgroundColor = Colors.Red,
TextColor = Colors.White,
Padding = 5,
FontSize = 12,
};
buttonDelete.Clicked += async (sender, e) =>
{
if (sender is Button btn && btn.BindingContext is Notification notification)
{
await _viewModel.Delete(notification.Id);
await _viewModel.Initialize();
}
};
buttonDelete.SetBinding(BindableObject.BindingContextProperty, ".");
grid.Add(titleLabel, 0, 0);
grid.Add(descriptionLabel, 0, 1);
grid.Add(buttonDelete, 1, 0);
border.Content = grid;
return border;
});
collectionView.ItemsLayout = new GridItemsLayout(1, ItemsLayoutOrientation.Vertical)
{
Span = 1 //doesn't do anything
};
Wenn hier niemand weiß, wie man das Problem behebt, muss ich zum XAML-Markup wechseln, dem C#-Markup fehlt die notwendige Dokumentation.