Füllen Sie den gesamten horizontalen Raum mit Rand
Posted: 20 Jan 2025, 14:09
Ich habe eine Sammlung von Objekten in Grid. Jedes Objekt wird innerhalb eines Rahmens angezeigt. Was ich brauche, ist, dass jede Randkachel den gesamten verfügbaren horizontalen Platz einnimmt. Im Moment habe ich eine Reihe von Rechtecken in verschiedenen Formen und Größen, die nicht wirklich gut aussehen.
Dies ist eine Inhaltsdefinition:
Dies ist die Definition der CollectionView
Ich habe keine Ideen mehr. Alles führt entweder zu nichts oder löst Fehler/Warnungen aus. LayoutOptions.Fill macht auch nichts.
Wenn hier niemand weiß, wie man das Problem behebt, muss ich zum XAML-Markup wechseln, dem C#-Markup fehlt die notwendige Dokumentation.
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.