Xaml 包含Xamarin格式网格的堆栈布局之间的间距
我对Xamarin比较陌生,我正在尝试实现这样的屏幕: 对于垂直列出的项目,我所做的是为每个项目创建单独的Xaml 包含Xamarin格式网格的堆栈布局之间的间距,xaml,xamarin,xamarin.forms,xamarin.android,xamarin.ios,Xaml,Xamarin,Xamarin.forms,Xamarin.android,Xamarin.ios,我对Xamarin比较陌生,我正在尝试实现这样的屏幕: 对于垂直列出的项目,我所做的是为每个项目创建单独的StackLayouts(以便将来如果我需要向特定项目添加某些内容,我可以这样做),这些项目本身有网格s,进一步有图标和标签。 类似这样的情况(我不能使用XAML,必须将其编码): ` 这是给我正确的必要项目; 但我无法给出两个项目之间的间距,令人烦恼的是。我尝试过像间距和填充这样的属性,但我没有找到确切的方法。 有人能告诉我一个我可以选择的方法吗? 那真是帮了大忙 首先,如果有必要,我
StackLayout
s(以便将来如果我需要向特定项目添加某些内容,我可以这样做),这些项目本身有网格
s,进一步有图标和标签
。
类似这样的情况(我不能使用XAML,必须将其编码):
`
这是给我正确的必要项目;
但我无法给出两个项目之间的间距,令人烦恼的是。我尝试过像间距
和填充
这样的属性,但我没有找到确切的方法。
有人能告诉我一个我可以选择的方法吗?
那真是帮了大忙 首先,如果有必要,我建议在将父项添加到根布局之前添加子项
因此,创建您的网格,将项目添加到该网格,然后将网格添加到父级堆栈布局
要添加间距,我将尝试间距
和/或边距
:
ysiStackLayout layoutPropertyDashboardIem = new ysiStackLayout() {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Center,
Spacing = 5 // Adding Spacing
};
Grid gridProperty = new Grid() {
HorizontalOptions = LayoutOptions.Center,
RowDefinitions = { new RowDefinition { Height = GridLength.Auto } },
ColumnDefinitions = { new ColumnDefinition {Width = GridLength.Auto} },
ColumnSpacing = 1,
Margin = new Thickness(5) // Adding Margin
};
ysiIcon iconProperty = new ysiIcon() {
Icon = IconSet.fa_AngleDoubleLeft,
IconSize = 30
};
gridProperty.Children.Add(iconProperty, 0, 0);
ysiLabel labelProperty = new ysiLabel { Text = "Property" };
gridProperty.Children.Add(labelProperty, 1, 0);
layoutPropertyDashboardIem.Children.Add(gridProperty); // Add children in reverse order up the layout tree
layoutDashboardItems.Children.Add(layoutPropertyDashboardIem); // Add children in reverse order up the layout tree
非常感谢你。我也会接受您关于在添加父元素之前添加子元素的建议。那样更整洁。
ysiStackLayout layoutPropertyDashboardIem = new ysiStackLayout() {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Center,
Spacing = 5 // Adding Spacing
};
Grid gridProperty = new Grid() {
HorizontalOptions = LayoutOptions.Center,
RowDefinitions = { new RowDefinition { Height = GridLength.Auto } },
ColumnDefinitions = { new ColumnDefinition {Width = GridLength.Auto} },
ColumnSpacing = 1,
Margin = new Thickness(5) // Adding Margin
};
ysiIcon iconProperty = new ysiIcon() {
Icon = IconSet.fa_AngleDoubleLeft,
IconSize = 30
};
gridProperty.Children.Add(iconProperty, 0, 0);
ysiLabel labelProperty = new ysiLabel { Text = "Property" };
gridProperty.Children.Add(labelProperty, 1, 0);
layoutPropertyDashboardIem.Children.Add(gridProperty); // Add children in reverse order up the layout tree
layoutDashboardItems.Children.Add(layoutPropertyDashboardIem); // Add children in reverse order up the layout tree