** Good afternoon!** Situation, there is another collectionView inside the collectionView. From the code I get to the methods and properties of the first collectionView by means of an attribute
x:Name="cv1"
But there is no access to the second collection from the code.
The error is this
The name "cv2" does not exist in the current context.
My XAML:
<CollectionView x:Name="cv1">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame Margin="5">
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Frame.GestureRecognizers>
<StackLayout>
<Label Text="{Binding Key}"/>
<CollectionView x:Name="cv2">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Label Text="{Binding DateCase}" HorizontalOptions="Start"/>
<Label Text="{Binding NumCase}" HorizontalOptions="CenterAndExpand"/>
<Label Text="{Binding Serial}" HorizontalOptions="CenterAndExpand"/>
<Label Text="{Binding Time}" HorizontalOptions="End"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Here is from the code:
cv1.ItemsSource = Cases; //There is access to the collection
cv2.ItemsSource = TimeLine; //There is no access to the collection
cv2.IsVisible = flag;
Tell me what's wrong? Which way to dig? Thanks.
Expected: By clicking on the Frame that contains the Collectionview, the isVisible property changed its value.
Turn out: That there is no access to the collectionView inside the Frame, which, in turn, is not inside the collectionView.
CodePudding user response:
Of course you cant access cv2 from code. The name CV2 is part of the data template, not your page.
What you actually ask is: How to access control in DataTemplate.
There is new CV2 generated, each time you insert CV1 item. You need to search for it, in the context of the current item. (If you need to use this approach)
What you actually have to do is:
- Use binding.
- Set x:DataType for your DataTemplate (CV1 item).
- Bind your CV2 ItemSource to a List to the set x:DataType Model.