2017-01-03 49 views
1

我想創建一個FlowListView,它具有相同數量的行和列,並且它包含具有相同高度和寬度的圖像。但是,FlowListView會扭曲行的高度,使其不等於列的寬度。如何將列的寬度綁定到RowHeight(如下所示)?FlowListview(Xamarin)中的方形圖像

<controls:FlowListView RowHeight="{Binding ColumnWidth}" ...> 
    <controls:FlowListView.FlowColumnTemplate> 
     <DataTemplate> 
     <Image ... /> 
     </DataTemplate> 
    </controls:FlowListView.FlowColumnTemplate> 
</controls:FlowListView> 
+0

我面臨同樣的問題。你解決了這個問題嗎? – AbsoluteSith

回答

0

我這樣做的代碼,而不是在XAML中,我發現它更容易申請,但它應該是類似的東西(也可能有比我更好的辦法)。

我在FlowListView控件上將'HasUnevenRows'屬性設置爲true。

Flow = new FlowListView() 
     { 
      VerticalOptions = LayoutOptions.FillAndExpand, 
      HorizontalOptions = LayoutOptions.FillAndExpand, 
      FlowColumnCount = 3, 
      FlowColumnTemplate = new DataTemplate(typeof(FlowCellImage)), 
      FlowTappedBackgroundDelay = 250, 
      FlowTappedBackgroundColor = Color.Gray, 
      SeparatorVisibility = SeparatorVisibility.Default, 
      IsPullToRefreshEnabled = true, 
      HasUnevenRows = true, 
      //Margin = thickness 
     }; 

然後在圖片我設置的「HeightRequest」屬性是「Application.Current.MainPage.Width/3」作爲我行曾在這3張照片。

public class FlowCellImage : FlowViewCell 
    { 
     private Image ImgPost; 
     public FlowCellImage() 
     { 
      ImgPost = new Image 
      { 
       Aspect = Aspect.AspectFill 
      }; 
      ImgPost.SetBinding(Image.SourceProperty, "ThumbnailUrl"); 

      HeightRequest = Application.Current.MainPage.Width/3; 
      Content = ImgPost; 
     } 
    }