填充

2017-02-10 58 views
1

我已经在Xamarin.Forms项目定义的下列细胞类型:填充

public MyCell() // constructor 
    { 
     var messageLabel = new Label 
     { 
      FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), 
      FontAttributes = FontAttributes.Bold, 
     }; 
     messageLabel.SetBinding(Label.TextProperty, new Binding("Message")); 

     var dateLabel = new Label 
     { 
      FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)) 
     }; 
     dateLabel.SetBinding(Label.TextProperty, new Binding("Date")); 

     var view = new StackLayout 
     { 
      Children = { messageLabel, dateLabel }, 
      Orientation = StackOrientation.Vertical, 
     }; 

     View = view; 
    } 

这被称为一个ListView内,像这样:

public MyPage() 
    { 
     var listView = new ListView() 
     { 
      ItemsSource = GetAllitems(), 
      ItemTemplate = new DataTemplate(typeof(MyCell)), 
     }; 

     Content = listView 
    } 

当这在屏幕上呈现出每个项目实际上已经与邻居压制在一起。我试图在MyCell类的StackLayout中添加填充,但这样做会导致文本离开屏幕。我想每个项目之间有差距。

我认为这可能是值得转换视图使用Xaml使这更清晰,所以如果它更容易实现Xaml我会接受这个答案!

+0

你有没有试过设置'ListView'的RowHeight? –

+0

这会修复所有人的身高吗?所以如果一个物品包装了一行文字,物品不会增加? – MartinM

+0

try ti将以下内容添加到您的ListView中Horizo​​ntalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand,然后添加一个填充 –

回答

1

在ListView上将HasUnevenRows属性设置为true。这样你可以更好地控制单元大小。

另外,将RowHeight保留为默认值(-1)。

+0

为清晰起见编辑答案,因为这对StackPanel中的Padding = new Thickness(15) – MartinM