0

I have a collection view with buttons in every row, when the button is press, the collectionview hides and then, another collectionview should showup with different data. The problem is this: the second collectionview never showup, it looks like the observablecollection didn't update the XAML interface, this is my code XAML

<Border >
    <Grid RowDefinitions="Auto,*,Auto" ColumnDefinitions="*">
        <ScrollView Grid.Row="1" Orientation="Horizontal" >
            <Grid>
                <!--datagrid de datos 1 -->
                <Grid RowDefinitions="Auto,*" HorizontalOptions="Center" IsVisible="{Binding VerMedidoresConProblemas,Mode=TwoWay}" >
                    <Grid Grid.Row="0" RowDefinitions="*" ColumnDefinitions="40,60">
                        <Label Grid.Column="0" Text="Field1"  />
                    </Grid>
                    <CollectionView  ItemsSource="{Binding Data1,Mode=TwoWay}" >
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <Grid RowDefinitions="*" ColumnDefinitions="40,Auto">
                                    <Label Grid.Column="0" Text="{Binding Number}" />
                                    <Button Grid.Column="1" 
                Command="{Binding BindingContext.SearchData2Command,Source={x:Reference RevisionBD}}" 
                                        CommandParameter="{Binding}"/>
                                </Grid>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>
                </Grid>
                <!--DataGrid de Data 2 -->
                <Grid RowDefinitions="Auto,*" IsVisible="{Binding VerData2,Mode=TwoWay}">
                    <Grid Grid.Row="0" RowDefinitions="*" ColumnDefinitions="40,60">
                        <Label Grid.Column="0" Text="AnotherField1"  />
                        <Label Grid.Column="1" Text="AnotherField2"  />
                    </Grid>
                    <CollectionView Grid.Row="1" 
                        ItemsSource="{Binding  Data2,Mode=TwoWay}" >
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <Grid RowDefinitions="*" ColumnDefinitions="40,60,100,150,150">
                                    <Label  Grid.Column="0" Text="{Binding Field_1}" />
                                    <Label  Grid.Column="1" Text="{Binding Field_2}" />
                                </Grid>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>
                </Grid>
            </Grid>
        </ScrollView>
    </Grid>
</Border>

My simplified viewmodel is this:

       [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(Data1))]
        bool verData1;

        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(Data2))]
        bool verData2;

        [ObservableProperty]
        ObservableCollection<myclass1> data1;

        [ObservableProperty]
        ObservableCollection<myclass2> data2;

[RelayCommand]
async void SearchData2(myclass1 objeto)
{
    Data2=new ObservableCollection<myclass2>(await Services.GetData2(objeto.Id));
    VerData2= true;
}

I'm using MAUI, .Net 7, my VS2002 is the version 17.5.4

I'm sure that the "Data2" collection gets data, the command is working good, the problem is the update of the interface, Any Idea where is the problem?

KillemAll
  • 633
  • 1
  • 10
  • 25
  • *"I'm sure that the "Data2" collection gets data"* "I'm sure" is not reassuring. Have you set a breakpoint on that line, then F10 to go to next line. Then examined Data2 to see that it has the data? – ToolmakerSteve May 18 '23 at 21:38
  • What platform did you use? – Liqun Shen-MSFT May 19 '23 at 03:13
  • I cannot reproduce this issue based on the code. – Liqun Shen-MSFT May 19 '23 at 05:06
  • I am testing in Windows,.. – KillemAll May 19 '23 at 14:37
  • I've change the second collection view using listbox with a template using TextCell, for the Data2 collection, and it works, but if in the template I put a label ... is the same problem, doesn't work, really strange – KillemAll May 19 '23 at 14:40
  • ToolmakerSteve, of course I've put breakpoints, that's why I'm sure about it – KillemAll May 19 '23 at 14:41
  • Strange, your code works well on my side windows platform. According to your description, the binding seems not the issue. Could you show more details about Xaml? – Liqun Shen-MSFT May 20 '23 at 08:59
  • you just given me the clue, the problem is not my viewmodel, is the XAML, the one I showed here is a simplified version, so this works, the real one doesn't, so I did rewrite the XAML and works! thanks! I guess I was having visibility or overlapping problems, well, sometimes is better rewrite :) Thanks for your time. – KillemAll May 23 '23 at 14:15
  • Glad you solved it. You could also post and mark your answer below. That may help others with similar issue. Thanks. – Liqun Shen-MSFT May 29 '23 at 05:35

0 Answers0