FlowListview中的方形图像(Xamarin)

时间:2017-01-03 13:36:55

标签: c# image xaml xamarin

我想创建一个具有相同行数和列数的FlowListView,它包含具有相同高度和宽度的图像。但是,FlowListView会扭曲行的高度,使其不等于列的宽度。如何将列的宽度绑定到RowHeight(如下所示)?

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

1 个答案:

答案 0 :(得分:0)

我在代码中而不是在Xaml中这样做,因为我发现它更容易应用但它应该是类似的(并且可能比我的更好)。

我设置了'HasUnevenRows&#39; FlowListView控件的属性为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
        };

然后在图像上我设置了&#39; HeightRequest&#39;属性为&#39; Application.Current.MainPage.Width / 3&#39;因为我的行中有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;
        }
    }