2015-05-29 96 views
0

如何强制我的TemplateItem扩展并填充ListView的整个宽度?XamarinForms ListView项填写

正如你在屏幕截图中看到的那样,listView有一个红色背景,而我的项目有一个白色背景。

的DataTemplate中的代码:

<DataTemplate x:Key="InformationMessageTemplate"> 
    <StackLayout Orientation="Horizontal" BackgroundColor="#FFFFFF" HorizontalOptions="FillAndExpand"> 
     <Label FontAttributes="Bold" Text="{Binding Sender}" /> 
     <Label Text=" chegou na sala" HorizontalOptions="FillAndExpand"/> 
    </StackLayout> 
    </DataTemplate> 

enter image description here

回答

2

尝试把StackLayout在ViewCell:

<DataTemplate x:Key="InformationMessageTemplate"> 
    <ViewCell> 
     <ViewCell.View> 
      <StackLayout Orientation="Horizontal" BackgroundColor="#FFFFFF" HorizontalOptions="FillAndExpand"> 
       <Label FontAttributes="Bold" Text="{Binding Sender}" /> 
       <Label Text=" chegou na sala" HorizontalOptions="FillAndExpand"/> 
      </StackLayout> 
     </ViewCell.View> 
    </ViewCell> 
    </DataTemplate> 
+0

感谢您的建议,但没有工作,仍然是相同的东西=( –

+0

嗯,这很奇怪 - 我有类似的情况,它似乎为我工作 - 你可以发布整个ListView Xaml? – codechinchilla

+1

你试过了吗?将布局的填充设置为0?特别是StackLayout,我不确定ListView是否具有填充属性,但是甚至可能您的ContentPage在右侧具有填充。 –