簡體   English   中英

如何使用自定義StackLayout大小的Xamarin Forms創建Listview

[英]How to create a listview with custom StackLayout size Xamarin Forms

我正在嘗試使用圖像和標簽創建ListView,但是問題是,我無法與StackLayout一起調整圖像的大小。 那是我的XAML代碼:

<ListView  x:Name="listView">
<ListView.ItemTemplate>
  <DataTemplate>
    <ViewCell>
      <StackLayout BackgroundColor="#eee"
      Orientation="Vertical">
        <StackLayout Orientation="Vertical">
          <Image  Source="{Binding image}" />
          <Label Text="{Binding title}"
          TextColor="#f35e20" />
          <Label Text="{Binding subtitle}"
          HorizontalOptions="StartAndExpand"
          TextColor="#503026" />
        </StackLayout>
      </StackLayout>
    </ViewCell>
  </DataTemplate>
</ListView.ItemTemplate>

我嘗試添加Image HeightRequestWidthRequest的道具,並且圖像確實發生了變化,但是StackLayout沒有變化

那就是結果: 在此處輸入圖片說明

那就是我想要的: 在此處輸入圖片說明

從我的意見,設置ListView.HasUnevenRows = true ,這樣的ListView不會限制您單元的大小,然后你需要讓UI知道,電池的大小通過運行改變ViewCell.ForceUpdateSize()的實例ViewCell ,進行了其Image調整大小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM