show an age when collectionview is done

Eduardo Gomez Romero 1,355 Reputation points
2024-11-28T00:02:18.2633333+00:00

I have a page, that everything gets the data by binding

 <Grid
     RowDefinitions="Auto,Auto,*,*"
     RowSpacing="5">

     <ActivityIndicator
         HorizontalOptions="CenterAndExpand"
         IsRunning="{Binding IsLoading}"
         IsVisible="{Binding IsLoading}"
         VerticalOptions="CenterAndExpand" />

     <Label
         Padding="0,5,0,0"
         FontAttributes="Bold"
         HorizontalTextAlignment="Center"
         Text="{x:Binding SelectedTurbine.Turbine.Name}"
         VerticalOptions="Center" />

     <Label
         Grid.Row="1"
         HorizontalTextAlignment="Center"
         Text="{x:Binding SelectedTurbine.Turbine.Address}"
         VerticalOptions="Center" />

     <Grid
         Grid.Row="2"
         Margin="2"
         Padding="10"
         ColumnDefinitions="*,*"
         ColumnSpacing="2"
         HorizontalOptions="Center"
         RowDefinitions="*,*,*,*,*"
         RowSpacing="2">

         <Border>
             <Label
                 Padding="10"
                 FontAttributes="Bold"
                 Text="{x:Static rex:AppResource.TurbineInstalationDateTime}"
                 VerticalOptions="Center" />
         </Border>

         <Border Grid.Row="1">
             <Label
                 Padding="10"
                 FontAttributes="Bold"
                 Text="{x:Static rex:AppResource.TubinePower}"
                 VerticalOptions="Center" />
         </Border>

         <Border Grid.Row="2">
             <Label
                 Padding="10"
                 FontAttributes="Bold"
                 Text="{x:Static rex:AppResource.TurbineCapacity}"
                 VerticalOptions="Center" />
         </Border>

         <Border Grid.Row="3">
             <Label
                 Padding="10"
                 FontAttributes="Bold"
                 Text="{x:Static rex:AppResource.TurbineEmission}"
                 VerticalOptions="Center" />
         </Border>

         <Border Grid.Row="4">
             <Label
                 Padding="10"
                 FontAttributes="Bold"
                 Text="{x:Static rex:AppResource.TurbineCarbonRemoval}"
                 VerticalOptions="Center" />
         </Border>

         <Border Grid.Column="1">
             <Label
                 Padding="10"
                 FontAttributes="Bold"
                 Text="{x:Binding SelectedTurbine.Turbine.StringifyInstalationDate}"
                 VerticalOptions="Center" />
         </Border>

         <Border
             Grid.Row="1"
             Grid.Column="1">
             <Label
                 Padding="10"
                 FontAttributes="Bold"
                 Text="{x:Binding SelectedTurbine.Turbine.Power,
                                  StringFormat='{0} kW'}"
                 VerticalOptions="Center" />
         </Border>

         <Border
             Grid.Row="2"
             Grid.Column="1">
             <Label
                 Padding="10"
                 FontAttributes="Bold"
                 Text="{x:Binding SelectedTurbine.Turbine.CapacityFactor}"
                 VerticalOptions="Center" />
         </Border>

         <Border
             Grid.Row="3"
             Grid.Column="1">
             <Label
                 Padding="10"
                 FontAttributes="Bold"
                 Text="{x:Binding SelectedTurbine.Turbine.Co2EmissionOffset,
                                  StringFormat='{0} kg CO₂/kWh'}"
                 VerticalOptions="Center" />
         </Border>

         <Border
             Grid.Row="4"
             Grid.Column="1">
             <Label
                 Padding="10,0,0,0"
                 FontAttributes="Bold"
                 FontSize="Medium"
                 Text="{x:Binding SelectedTurbine.Turbine.FinalCo2Removed,
                                  StringFormat='{0} kg CO₂'}"
                 VerticalOptions="Center" />
         </Border>
     </Grid>

     <CollectionView
         Grid.Row="3"
         Margin="0,0,0,20"
         HorizontalOptions="CenterAndExpand"
         ItemsSource="{x:Binding SelectedTurbine.Turbine.ImagesURLs}">

         <CollectionView.ItemsLayout>
             <LinearItemsLayout
                 ItemSpacing="5"
                 Orientation="Horizontal" />
         </CollectionView.ItemsLayout>

         <CollectionView.ItemTemplate>
             <DataTemplate x:DataType="x:String">
                 <Image
                     Aspect="AspectFit"
                     Source="{Binding}"
                     VerticalOptions="Center" />
             </DataTemplate>
         </CollectionView.ItemTemplate>

     </CollectionView>
 </Grid>


 public partial class TurbineDetailPageViewModel: ObservableObject
 {
     [ObservableProperty]
     TurbinePin? selectedTurbine;
 }

in my SelectedTurbines, I have a list of turbines, that are store in azure

 <CollectionView
         Grid.Row="3"
         Margin="0,0,0,20"
         HorizontalOptions="CenterAndExpand"
         ItemsSource="{x:Binding SelectedTurbine.Turbine.ImagesURLs}">

         <CollectionView.ItemsLayout>
             <LinearItemsLayout
                 ItemSpacing="5"
                 Orientation="Horizontal" />
         </CollectionView.ItemsLayout>

         <CollectionView.ItemTemplate>
             <DataTemplate x:DataType="x:String">
                 <Image
                     Aspect="AspectFit"
                     Source="{Binding}"
                     VerticalOptions="Center" />
             </DataTemplate>
         </CollectionView.ItemTemplate>

     </CollectionView>


so, my SelectedTubine has a list with a link to the container in azure

Question

How can I make the grid of the page visible, when all my pictures are visible in my collection page

Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-11-29T02:50:51.71+00:00

    Hello,

    Firstly, open your InitializeAsync method, change the return type to Task<bool>, if the LoadOrInitializeTurbineAsync load finished, you can return the true value, others retrun false value.

    public async Task<bool> InitializeAsync()
     {
         await firestoreService.InitializeFirestoreAsync();
         _firestoreDb = firestoreService.GetFirestoreDb();
         if (_firestoreDb != null) {
              await LoadOrInitializeTurbineAsync().ContinueWith((e) =>
    
             {
    
                 return true;
    
             });
         }
         return false; 
       }
    

    Then Open your ViewModel. add a isLoadFinished property, if set the return value to this IsLoadFinished property.

     [ObservableProperty]
    
     bool isLoadFinished;
    
     IsLoadFinished = await  turbinesService.InitializeAsync();
    

    You can bind a IsVisible value to IsLoadFinished.

     <Grid
         IsVisible="{Binding IsLoadFinished}"
         RowDefinitions="Auto,Auto,*,*"
         RowSpacing="5">
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.