簡體   English   中英

用Xamarin表格制作畫廊表格

[英]Making a gallery form in Xamarin Form

我正在制作一個照相館,它從URL中獲取圖像名稱的JSON。 使用列表形式確實不能提供良好的用戶體驗,因此我計划更改網格形式。 嘗試一些我在stackoverflow中找到的代碼。 問題是我嘗試創建一個數組綁定,以便隨着數據庫中照片數量的增加,應用程序將為其添加一個新的網格並顯示它。

<Grid x:Name="grid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Image Grid.Column="0" Source="{Binding Images[0].MyImageUrl}" />
        <Image Grid.Column="1" Source="{Binding Images[1].MyImageUrl}" />
        <Image Grid.Column="2" Source="{Binding Images[2].MyImageUrl}" />
    </Grid>

這是XAML格式,現在我試圖創建一個與此綁定的CS,它將自動創建一個網格文件以顯示JSON文件中的圖像。 提前致謝

Grid沒有像ItemsSource這樣的屬性。 因此,您至少需要以編程方式添加圖像。

protected override void OnAppearing ()
{
   base.OnAppearing();

   // Create cols for each img
   for(int col = 0; col < Images.Length; ++col){
       grid.ColumnDefinitions.Add(new ColumnDefinitions { Width = new GridLenght(1, GridUnitType.Star)});
   }
   // Populate grid
   for(int col = 0; col < Images.Length; ++col){
       grid.Children.Add(new Image { source = Images[col] },0,col);
   }
}

如果您想在XAML中做所有事情。 使用FlowListView

編輯:我做了2 for's原因,因為我不確定在創建ColumnDefinition時是否嘗試Add 無論如何,嘗試一種或另一種方法。

暫無
暫無

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

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