Xamarin.forms 如何在MasterDetail页面上的项目之间添加空间?

Xamarin.forms 如何在MasterDetail页面上的项目之间添加空间?,xamarin.forms,Xamarin.forms,我想知道如何将项目分开,而不是彼此非常接近。现在,iOS上的每个项目都太接近了。 我尝试在ListView和StackLayout上设置边距和空间,但每个项目之间的空间没有改变。为了增加空间,我想我需要对图像单元做些什么。图像单元格是从文本单元格继承而来的,但没有为边距或空格设置属性。有人知道怎么玩这个把戏吗 public MasterPageCS () { var masterPageItems = new List<MasterPageItem> (); mast

我想知道如何将项目分开,而不是彼此非常接近。现在,iOS上的每个项目都太接近了。 我尝试在ListView和StackLayout上设置边距和空间,但每个项目之间的空间没有改变。为了增加空间,我想我需要对图像单元做些什么。图像单元格是从文本单元格继承而来的,但没有为边距或空格设置属性。有人知道怎么玩这个把戏吗

public MasterPageCS ()
{
    var masterPageItems = new List<MasterPageItem> ();
    masterPageItems.Add (new MasterPageItem {
        Title = "Contacts",
        IconSource = "contacts.png",
        TargetType = typeof(ContactsPageCS)
    });
    masterPageItems.Add (new MasterPageItem {
        Title = "TodoList",
        IconSource = "todo.png",
        TargetType = typeof(TodoListPageCS)
    });
    masterPageItems.Add (new MasterPageItem {
        Title = "Reminders",
        IconSource = "reminders.png",
        TargetType = typeof(ReminderPageCS)
    });

    listView = new ListView {
        ItemsSource = masterPageItems,
        ItemTemplate = new DataTemplate (() => {
            var imageCell = new ImageCell ();   //This one!!!!
            imageCell.SetBinding (TextCell.TextProperty, "Title");
            imageCell.SetBinding (ImageCell.ImageSourceProperty, "IconSource");
            return imageCell;
        }),
        VerticalOptions = LayoutOptions.FillAndExpand,
        SeparatorVisibility = SeparatorVisibility.None
    };

    Padding = new Thickness (0, 40, 0, 0);
    Icon = "hamburger.png";
    Title = "Personal Organiser";
    Content = new StackLayout {
        VerticalOptions = LayoutOptions.FillAndExpand,
        Children = {
            listView
        }
    };
}
public MasterPageCS()
{
var masterPageItems=新列表();
masterPageItems.Add(新建MasterPageItem){
Title=“联系人”,
IconSource=“contacts.png”,
TargetType=typeof(ContactsPageCS)
});
masterPageItems.Add(新建MasterPageItem){
Title=“TodoList”,
IconSource=“todo.png”,
TargetType=typeof(TodoListPageCS)
});
masterPageItems.Add(新建MasterPageItem){
Title=“提醒”,
IconSource=“ememployers.png”,
TargetType=typeof(提醒页面)
});
listView=新建listView{
ItemsSource=masterPageItems,
ItemTemplate=新数据模板(()=>{
var imageCell=new imageCell();//这一个!!!!
imageCell.SetBinding(TextCell.TextProperty,“标题”);
imageCell.SetBinding(imageCell.ImageSourceProperty,“IconSource”);
返回图像单元;
}),
VerticalOptions=LayoutOptions.FillAndExpand,
SeparatorVisibility=SeparatorVisibility.None
};
填充=新厚度(0,40,0,0);
Icon=“hamburger.png”;
Title=“个人组织者”;
内容=新的堆栈布局{
VerticalOptions=LayoutOptions.FillAndExpand,
儿童={
列表框
}
};
}

有人问了类似的问题:

使用ViewCell,这样可以控制布局和间距,内置的布局模板只对基本内容有用

这里有一个关于使用ViewCell的示例

我的建议是在可能的情况下使用网格进行自定义布局,更好的性能和更少的跨平台麻烦,stacklayouts可能会在数据模板的iOS中引起问题,尤其是高度是自动的

如果您使用TextCell和ImageCell,那么表单会根据您的最佳猜测来帮助您

此外,如果为MasterPageItem子级使用网格,请在网格中将行间距设置为0,只有这样,在数据模板中设置的页边距才会开始按预期工作