2015-05-29 92 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在右側具有填充。 –